Home › Forums › Add-ons › Repeater Field › Use a radio button across a Repeater › Reply To: Use a radio button across a Repeater
thank you for your help John.
since there is no “out-of-the-box” method, I enacted plan B.
replaced radio buttons with checkboxes and added some JS.
here it is, in case somebody else would ever need it:
(function($){
$(document).ready(function() {
// cache the checkboxes
var
$acftable = $('table.acf-table'),
$checkboxes = $acftable.find('ul.acf-checkbox-list input');
// delegation will make sure click on newly added elements will trigger the function
$acftable.on('click', 'ul.acf-checkbox-list input', function(){
// uncheck all
$checkboxes.prop('checked', false);
// check the clicked one
$(this).prop('checked', true);
});
// if checkboxes exists on the page, but none is checked ... then
if ($checkboxes.length && !$checkboxes.is('checked').length) {
// ... check the first
$checkboxes.eq(0).click();
}
});
})(jQuery);
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.