Home Forums Backend Issues (wp-admin) Field Object shows load_field as working, but it doesn't render that way


Field Object shows load_field as working, but it doesn't render that way

  • 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.

  • Hi John,

    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.

    Thank You

    $disabled = array();
    foreach ($field['choices'] as $value => $label) {
      $disabled[$value] = true;
    $field['disabled'] = $disabled;
    return $field;
Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Field Object shows load_field as working, but it doesn't render that way’ is closed to new replies.