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');
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.