Limiting number of checked boxes in Dynamic field

By: Julius hernández | Asked: 06/28/2022
ForumsCategory: General questionsLimiting number of checked boxes in Dynamic field
Julius hernándezJulius hernández asked 2 years ago

According to this JS code, I can limit the number of checked boxes in a Checkbox field.

 

 

 

<script type="text/javascript">


jQuery(document).ready(function($){


var limit = 3;// Change 3 to your limit


$('input[name="item_meta[364][]"]').change(function(){


var checkbox_num = $("input[name='item_meta[364][]']:checked").length;


if ( checkbox_num > limit ) {

this.checked = false;

}


});


});


</script>

 

 

 

And it works well, even there is a built-in mode to accomplish this.
But it does not work however in the checkboxes mode of a Dynamic field. I tried even changing "input" by "select", but it keeps failing. Unfortunately, checkboxes mode of Dyn fields has not a Limit selection option.
What's the secret here? Not referencing it correctly?

(EDIT: I tried to change this question to Code Help editing it but I couldn't.)

 

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right