Skip Navigation

[Resolved] Limit number of choices to be selected in dropdown of categories on a post form

This support ticket is created 5 years 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 5 years ago.

Assisted by: Luo Yang.

Author
Posts
#1444743

Tell us what you are trying to do?

I want users to be able to select up to 2 categories for a custom post type when using a toolset form on the front end. I have the form set for a single select, but would like to offer more choices.

Is there any documentation that you are following?

i have looked here - https://toolset.com/forums/topic/limit-number-of-checkboxes-allowed/ but that is for checkboxes. can it also be applied to a select drop down?

Is there a similar example that we can see?

What is the link to your site?

hidden link

#1445853
multple-select.JPG

Hello,

1) You can turn the single select of taxonomy field in Toolset form into multple select with option:
Display taxonomy as a select dropdown with multiple selection
see the screenshot: multple-select.JPG

If you are using "Expert mode", you can setup the taxonomy field shortcode, like this:
[cred_field field='category' force_type='taxonomy' output='bootstrap' display='select']
Please replace "category" with your custom taxonomy slug

2) Then use below JS codes to setup the limitations:

jQuery(document).on('cred_form_ready', function(){
  var tema_limit = 2;

  jQuery('[name="category[]"]').on('click', 'option', function() {
      if(jQuery('[name="category[]"] option:selected').length > tema_limit) {
         jQuery(this).removeAttr("selected");
     }
  });
});

Same as above, please replace "category" with your custom taxonomy slug, tand test again