Skip Navigation

[Resolved] single select check box taxonomy post form

This support ticket is created 5 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by olivierF 5 years, 2 months ago.

Assisted by: Beda.

Author
Posts
#1328305

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

#1328587

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!

#1328647

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.

#1328655

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