Skip Navigation

[Resolved] Unable to restrict taxonomy dropdown selection limit

This support ticket is created 4 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by himanshuS 4 years ago.

Assisted by: Minesh.

Author
Posts
#1890751

I want to limit the number of taxonomy a user can select on a front end form. I am using the code provided in one of the tickets and it's not working. What am I missing?

Code:
//limit selection of 3 skills in an endorsement
jQuery(document).ready('cred_form_ready',function($){
var tema_limit = 3;

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

Reference: https://toolset.com/forums/topic/limit-number-of-choices-to-be-selected-in-dropdown-of-categories-on-a-post-form/

#1890799

Updated code:
//limit selection of 3 skills in an endorsement
jQuery(document).ready('cred_form_ready',function($){
var tema_limit = 3;

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

#1891375

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Again, I will require problem URL where I can see the form you added as well as access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1891449

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok - I see that the issue belongs to the same form.

I've adjusted the JS code as given under within your form's JS box:
=> hidden link

//limit selection of 3 skills in an endorsement
jQuery(document).ready(function($){
  var tema_limit = 3;
 
  jQuery("select[name='skill-category[]']").on('click', 'option', function() {
      if(jQuery("select[name='skill-category[]'] option:selected").length > tema_limit) {
         jQuery(this).removeAttr("selected");
         alert("Maximum 3 Options allowed.")
     }
  });
});

Can you please confirm it works as expected: hidden link

#1891587

My issue is resolved now. Thank you!