Problem with multiple fields when at least one of them is disabled

Created on 19 July 2022, almost 2 years ago
Updated 22 May 2024, about 1 month ago

Problem/Motivation

When you have more than one field using Autocomplete Deluxe widget and make at least one of them disabled (by adding #disabled = TRUE), then other fields using this widget are not working (autocomplete functionality is broken). I can see Cannot read properties of undefined (reading 'multiple') error in JS.

Steps to reproduce

  1. Create a custom node.
  2. Add two entity_reference fields to this entity (field_a and field_b).
  3. Select Autocomplete Deluxe widget in form display for both of them.
  4. Make field_a disabled by adding $elements['#disabled'] = TRUE; in hook_field_widget_multivalue_form_alter function.
  5. Try to add your entity. You should see that field_a is disabled and field_b is not working.

Here's my code:

function mymodule_field_widget_multivalue_form_alter(
  array &$elements,
  FormStateInterface $form_state,
  array $context
): void {
    $fieldDefinition = $context['items']->getFieldDefinition();

    if ($fieldDefinition->getName() === 'field_a') {
      $elements['#disabled'] = TRUE;
    }
  }
}
πŸ› Bug report
Status

Fixed

Version

2.0

Component

User interface

Created by

πŸ‡΅πŸ‡±Poland tivi22

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

Merge Requests

Comments & Activities

Not all content is available!

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

Production build 0.69.0 2024