['#disabled'] = TRUE doesnt work

Created on 30 October 2017, almost 7 years ago
Updated 5 September 2023, about 1 year ago

When you try to disable field in form alter, you're still able to add categories. ['#disabled'] = TRUE doesnt work propertyl

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇨🇿Czech Republic mkolar

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇧🇪Belgium Dasm2000

    Setting the disabled option only sets the "multiselect-selected" select field to disabled.
    The "multiselect-available" select field is not set disabled and neither are the + and - buttons.
    This results in a user still being able to select an available option and have it added by clicking the + button.
    Just disabling the buttons should do the trick.

  • 🇮🇳India jigish.addweb

    I tried different methods to disable the multiselect field, and it worked with the CSS property pointer-events: none;. Although the user interface looks different, but it functions correctly.

    /**
    * Implements hook_form_alter().
    */
    function multiselect_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
    /**
    * Disabled the field, but it only disables the selected option list and label.
    */
    // $form['field_tags']['#disabled'] = TRUE;

    /**
    * Disabled the field using the 'disabled' attribute.
    * However, this only affects the labels for 'Selected Options' and 'Available Options'.
    */
    // $form['field_tags']['#attributes']['disabled'] = TRUE;

    /**
    * Disable user interaction with the field using CSS ('pointer-events: none;').
    * The disabled appearance may differ from the default, but functionality remains intact.
    */
    $form['field_tags']['#attributes']['style'] = 'pointer-events: none;';
    }

Production build 0.71.5 2024