Support

Account

Home Forums Front-end Issues Readonly radio field

Solved

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');
    
  • I also got the same error , please help me to find out the solution for this.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.