Hey Elliot and team!
I am interested in limiting the checkboxes on one of our fields. I did some research and found some js that should handle this, but I cannot seem to get it to work as expected. I was hoping a second set of eyes could see where I was off.
Here is the code I am using:
add_action('admin_print_scripts','ssm_inline_scripts');
function ssm_inline_scripts() { ?>
<script>
var limit = 4;
jQuery('.field_key-field_5408de6b05aa9 input[type='checkbox']').on('change', function(evt) {
if(jQuery(this).siblings(':checked').length >= limit) {
this.checked = false;
}
});
</script>
<?php }
Any thoughts? Thanks! -Rich
This is how I added support to limit the number of selectable checkboxes:
acf.add_action('ready', function( $el ){
var limit = 4,
selector = '.acf-field-573408b96dcd4 :checkbox',
$boxes = $(selector),
limiter = function () {
if ($boxes.filter(':checked').length >= limit) {
// this.checked = false;
$boxes.not(':checked').attr('disabled', true).prop('disabled', true);
} else {
$boxes.filter(':disabled').removeAttr('disabled').prop('disabled', false);
}
};
if ($boxes.length) {
limiter();
}
$(document).on('change.aqcpe.acf.careers', selector, limiter);
});