Support

Account

Home Forums Bug Reports disable via prepare_field

Solving

disable via prepare_field

  • Hi

    When adding a prepare_field filter that disables or makes a field readonly by adding $field['disabled'] = true; for certain field types doesn’t work.

    ‘user’ field: the select2 still renders.

    ‘true_false’ field: the field output is not changed where I was expecting "disabled"="disabled"

    Thanks

  • Not all select 2 fields can be disabled. Actually, I’m not sure that any select2 fields can be disabled.

    In the case of the true/false field it could be something in the code for the new UI for these fields. Are you seeing the problem with the stylized UI on or off?

  • One year passed and we still are here… I can’t use $field[‘disabled’] = true; for ‘true/false’-field, because that doesn’t work. It’s a bit strange to have the functional which don’t work with two type of field. Why that is?

    “Are you seeing the problem with the stylized UI on or off?” – Yes.
    If I make the field[‘ui’] = 0; then will $field[‘disabled’] = true work? Where I need do it? I mean now I work into ‘acf/prepare_field’.

  • The stylized UI uses a select2 field and not a checkbox field. Select2 fields cannot be disabled. It might be possible to do by adding custom JavaScript, but to be honest I don’t know for sure. But it can’t be done using the prepare field hook or in PHP using any hook.

  • Hello I wanted to state that I came across this issue and I believe I was able to make this work as expected for the true_false field, now I know this will be removed upon an update but maybe this can make it’s way into the production version??

    I added this to line 67 of the class-acf-field-true_false.php file.

    
    // disabled
    if( array_key_exists( 'disabled', $field ) && $field['disabled']) {
      $input['disabled'] = true;
      $hidden['value'] = $field['value'] ? true : false;
    }
  • Any chance this will make it soon to the core plugin?

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

The topic ‘disable via prepare_field’ is closed to new replies.