Hi,
I can't create a checkbox in a publication form with only one possible choice. I specify that it must be a checkbox.
I have this code
[cred_field field = 'project-type' placeholder = "Project Type" force_type = 'taxonomy' display = 'checkbox' single_select = 'true']
But it doesn't work
Thanks a lot
Olivier
Yes, because just as in WordPress, taxonomy terms cannot be limited to be chosen.
Single Select as you use it is not for checkboxes, it's for select inputs (many or just one choosable)
With this, you can restrict the chosen term to just one possible, but not restrict how many options are actually offered.
Generally, you cannot limit it to only one option offered.
You would have an issue as of "what" term precisely to be the sole one offered, and second, this may not always be the same.
So WordPress, and hence Toolset Forms, offers methods to add any Term existing, or new ones, to a post
I think you need a way to let users submit posts and choose just ONE of MANY terms, right?
But the choice is still the users, I assume.
In this case, you must use Select type and single select set to true:
See also https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field > single_select:
Optional. Used by fields for Hierarchical Taxonomies (like Categories) to signify that the select field does not support multi-select mode.
If instead, you want ONE checkbox, that always offers the same option, you best use a Generic Field and some Custom Code, which when the field is checked and the form submitted, adds a specific term to the post.
If your choice is the last one and you need help with the custom code, please ask me - I can show examples of this and help you review your code.
Thanks!
Hi Beda,
Thank you for your help.
The customer absolutely wants a checkbox with a unique choice. It must be based on taxonomies. Can you help me for the custom code? Thank you.
I finally found a solution with JS.
$('input.wpt-form-checkbox').on('change', function() {
$('input.wpt-form-checkbox').not(this).prop('checked', false);
});
Thanks
Olivier