Home Forums Add-ons Repeater Field Use a radio button across a Repeater


Use a radio button across a Repeater

  • Hi,

    I set-up an Options Page. It does contain a Repeater Field consisting of a radio button and a textarea field.

    Each repeater group is used to store a different version of a text that is displayed in a specific page of the website.

    is there a way to have the radio button to work across those repeater fields? so that I can use it to pick which group is the default to be used?

  • If I understand correctly, you have a repeater and in each row you select a page on the site and enter the text to be shown on that page? What you want is that if there isn’t text entered for a specific page to specify which of the other rows to show?

  • no, sorry, I wasn’t clear in my explanation.

    I have an Options Page dedicate to a specific website page (i.e. Contact Us)
    in it I have a repeater, and in each row, I store a some text (textarea), and a label (text field)

    I do have posts that when in a specific category, do have a timepicker and a select box that is populated with the labels (text field) in each row of the Options Page … this way I can choose which text I want to use in the Contact Us page for a specific time span (i.e. during sales).

    in the Options Page’s repeater I also included a radio button.
    I would like for it to work across the Repeater’s rows so that I can pick the default text to be selected when populating the Select box for the first time or to be used in the Contact Us page when no posts in that category are present.

    I hope I made sense…

  • There isn’t a way to do this directly. There are a couple of options that I can think of but they have problems.

    Since you are populating the fields in the page dynamically from the options you could add another radio button separate from your repeater to somehow indicate the default value. You could populate the values of this radio field dynamically based on the values entered into the repeater. The problem with this one is that the new radio field won’t populate with anything until you save the options… unless you build some javascript/ajax functions to do it… which I wouldn’t be able to help you with.

    The other choice is to put a checkbox in the repeater for “Use as default”. The problem with this one is that there would be nothing to stop someone from checking multiple rows as defaults.

  • 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:

    	$(document).ready(function() {
    		// cache the checkboxes
    			$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 && !$'checked').length) {
    			//  ... check the first
  • Thanks for posting your solutions, I may actually use this at some point and I’m sure it will help others.

  • you are very welcome!

    I was in a hurry earlier, I just edited my English and cleaned up the JS (well, the jQuery) a bit.

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Use a radio button across a Repeater’ is closed to new replies.