Home › Forums › General Issues › Limit Number of Checkboxes to select › Reply To: Limit Number of Checkboxes to select
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);
});
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.