Support

Account

Home Forums General Issues Pre-Populate Radio Button Choices Reply To: Pre-Populate Radio Button Choices

  • The idea is a good one, but because you are using a repeater and the radio field is a sub field of the repeater, you can’t use acf/load_field. This will make all of the radio fields have the same choices.

    The can be done but you’re going to need to do it in JavaScript, and there might still be a problem getting the selected value to actually be selected. The reason being that if the selected value is not one of the choices when ACF loads the field then it will set none of them or the default to be currently selected for each of them and you’ll need to re-select the choice every time. Basically, in JavaScript when the page is ready you will need to read the values for your choices, then populate the radio field with your choices, the you’ll need to do an AJAX request to get the currently selected choice, if any and set the right radio button to be selected.

    You might want to take a look at some of my examples for dynamically generating field values in JS https://github.com/Hube2/acf-dynamic-ajax-select-example.

    Here are something you won’t find there

    
    // get the row that a field is in
    var $row = e.$el.closest('.row');