Home › Forums › Bug Reports › Choice field "Other" Repeater Issue
Hello,
First off, thanks so much for the amazing plugin, I can’t imagine building a site without ACF. 🙂
I’ve just encountered a bug when using a choice field (in this case radio buttons) within a repeater and choosing the “Add ‘other’ choice to allow for custom values” and the “Save ‘other’ values to the field’s choices” options. When an “other” value is entered ACF is renaming the Field Name.
For example, if the sub field name is foo
, within a repeater called bar
, when an “other” option is saved the sub-field name for foo
is renamed bar_4_foo
. Additional options continue to add onto the name like so: bar_1_bar_4_foo
. I’m using ACF Pro 5.3.8.
Thanks!
Where are you seeing this renaming? Can you do some copy and pasting of then exact names your seeing and where you’re seeing them? I just did a quick test and everything seems to be working correctly for me.
Hi John,
Sure, let me see if I can explain this better. So in this case my repeater name is upload_publication
. This repeater has a radio button sub-field, with a field name that was initially set to language
.
In the post edit screen the repeater shows up fine, with the default languages loaded into the radio button choices and a final ‘other’ option (added with the “Add ‘other’ choice to allow for custom field values”). When I fill out a value here and save the post, the new value is added to the list of options but the values set for all these options all go back to the default option. Going back to the Edit Field Group and opening the repeater, I can see that the Field Name has changed from language
to upload_publication_4_language
. Each time I add a new value in the post edit screen the field name is once again renamed, wth the additions tacking on to the start of the name; so it starts with upload_publication_4_language
but then becomes upload_publication_1_upload_publication_4_language
, etc. The number added seems to be related to which row of the repeater I’m editing; the first row adds a 1, and later rows (I think) are the row number minus 1 (so the fifth row adds a 4, etc).
Hope this is clearer! Thanks for looking into this issue.
Thanks for the detail, I’m seeing the same thing now that it’s clear where I should be looking. I will report this bug to the developer.
Hi Ria
Elliot here – ACF dev.
Thanks for the bug report.
I’ve got some code for you to test if that’s ok.
Can you please edit the file: fields/radio.php and replace the following function:
function update_value( $value, $post_id, $field ) {
// bail early if no value (allow 0 to be saved)
if( !$value && !is_numeric($value) ) return $value;
// save_other_choice
if( $field['save_other_choice'] ) {
// value isn't in choices yet
if( !isset($field['choices'][ $value ]) ) {
// get raw $field (may have been changed via repeater field)
// if field is local, it won't have an ID
$selector = $field['ID'] ? $field['ID'] : $field['key'];
$field = acf_get_field( $selector, true );
// bail early if no ID (JSON only)
if( !$field['ID'] ) return $value;
// update $field
$field['choices'][ $value ] = $value;
// save
acf_update_field( $field );
}
}
// return
return $value;
}
Try the problem again and let me know if it solves it.
Thanks
E
The topic ‘Choice field "Other" Repeater Issue’ is closed to new replies.
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.