- 🇧🇪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;';
}