Home › Forums › Front-end Issues › Readonly radio field
I have a acf_form();
in the front end which outputs a repeater. I want to make some rows readonly. Each row contains a radio button field.
The code below works great with text fields, but not with radio buttons. Any ideas?
function my_load_field($field) {
$field['readonly'] = 1;
return $field;
}
add_filter("acf/load_field/name=radio_button", "my_load_field");
Radio fields do not support readonly. It’s not ACF, it is the way that radio fields work. https://stackoverflow.com/questions/1953017/why-cant-radio-buttons-be-readonly
Thanks for your answer. Does the same go for disabled
? This code seems to work for me. Is it possible to achieve that with a filter for ACF radio fields?
<input disabled type="radio" name="" value="">
I’m pretty sure you can set a field to disabled https://www.advancedcustomfields.com/resources/acf-prepare_field/
$field['disabled'] = true;
but I am not entirely sure at the moment.
I tried that as well. But it only applies to my text fields.
function my_acf_prepare_field( $field ) {
$field['disabled'] = true;
return $field;
}
add_filter('acf/prepare_field', 'my_acf_prepare_field');
I just looked at the ACF code and it appears it allows more granular control for ratio fields, at least that’s the way it appears.
function my_acf_prepare_field( $field ) {
$field['disabled'] = array(
// set each value option you want to disable
'value1',
'value2',
// etc
);
return $field;
}
add_filter('acf/prepare_field', 'my_acf_prepare_field');
The topic ‘Readonly radio field’ 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.