Skip Navigation

[Resolved] Limit number of checkbox checked for a specific custom fields

This thread is resolved. Here is a description of the problem and solution.

Problem:

I'm trying to limit user on the number of checkbox they can check for a specific custom fields.

Solution:

It needs custom JS codes, for example:

https://toolset.com/forums/topic/limit-number-of-checkbox-checked-for-a-specific-custom-fields/#post-1214546

Relevant Documentation:

This support ticket is created 5 years, 1 month 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 2 replies, has 2 voices.

Last updated by jean-francoisB 5 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#1214522

I'm trying to limit user on the number of checkbox they can check for a specific custom fields.

This is the custom field :

<div class="form-group ">
<label>Category</label>
[cred_field scaffold_field_id='listing-category' field='listing-category' force_type='taxonomy' output='bootstrap' display='checkbox' label='Listing categories']
</div>

and this is what I added in Javascript :

$("input[type=checkbox][name=listing-category]").click(function() {

var bol = $("input[type=checkbox][name=listing-category]:checked").length >= 4;
$("input[type=checkbox][name=listing-category]").not(":checked").attr("disabled",bol);

});

I've been following instruction from that Thread and doesn't seems to work for me : https://toolset.com/forums/topic/possible-to-limit-number-of-checkboxes-a-user-can-select/

Do you have any suggestion for me?

Thank you,

#1214546

Hello,

I assume we are talking taxonomy field "listing-category" in a Toolset post form, if it is, the checkboxes HTML element name is "listing-category[]", for example, you can modify your JS codes as below:

$("input[name='listing-category[]']").click(function(e) {

  var bol = $("input[name='listing-category[]']:checked").length >= 4;
  $("input[name='listing-category[]']").not(":checked").attr("disabled",bol);

});

And test again.

#1214601

Thank You very much! It's all good now!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.