Hey ACF Pro experts,
I’m absolutely baffled by acf/load_field filter. When I think I have it working, I realize that I just don’t.
I’m using a Button Group (I also tested with Radio Buttons). But readonly or disabled doesn’t seem to work, or perhaps I’ve confused something. I’ve searched through almost 20 different responses since 2014 on ACF about using readonly or disabled and some responses seem to show resolution but I haven’t been able to get it to work.
I’ve got a load_field filter to check if a function exists, if it fails I want the option to display and be visible but not let the admin interact with it. Based on debugging the output of field object my filter settings are working so functionally it should operate fine.
However, the display of the field does not reflect the field object details.
Here is a screenshot of the output of fieldobject, the render in the settings and the code.
readonly is not supported by browsers in choice type fields (radio, checkbox, select), so you need to use disabled.
I just did some looking into disabling either a select field or a radio type of field, don’t recall which….
Anyway, my findings were that ACF allows granular control over disabling some fields. Lets say that you have a field with these choices.
value_1 : Value 1 value_2 : Value 2 value_3 : Value 3
You can disable any of these and leave the rest enabled. So if you want to disable value 2 to then do:
$field['disabled'] = array( 'value_2' => true );
I have not tested this on every field type that allows choices and like I said, I don’t remember which field I actually tested this on, all I can say is to give it a try and see what happens.
Thanks for reaching out and providing me some very useful information. This does work for radio button fields, I suspect it would also work for dropdowns and perhaps checkboxes. It does not work for the button group option even though its technically a radio button. I’m guessing the styling or jquery for the button group does not follow the acf disabled protocol at all or correctly.
I’m just going to switch to radio button. I only managed to get it to work by passing all the values as true in the disabled array. Just marketing a radio button field as disabled = 1 or disabled = true does not visually disable the whole field. Programmatically it seems the field object returns values as though it is disabled, but it doesn’t translate visually.
However, for radio button fields this code you’ve provided does work if you add all the values to it, essentially disabling all options.
You must be logged in to reply to this topic.
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!
© 2022 Advanced Custom Fields.