Fix the problem with multiple fields when at least one of them is disabled

Created on 19 July 2022, over 2 years ago
Updated 15 September 2024, 3 months 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;
    }
  }
}

Proposed resolution

not send js settings for disabled fields

Remaining tasks

  • βœ… File an issue
  • βœ… Addition/Change/Update/Fix
  • βœ… Testing to ensure no regression
  • βž– Automated unit testing coverage
  • βž– Automated functional testing coverage
  • βž– UX/UI designer responsibilities
  • βž– Readability
  • βœ… Accessibility
  • βž– Performance
  • βž– Security
  • βž– Documentation
  • βœ… Code review by maintainers
  • βž– Full testing and approval
  • βœ… Credit contributors
  • βœ… Review with the product owner
  • βœ… Release notes snippet
  • βœ… Release autocomplete_deluxe-2.0.4 β†’

API changes

  • N/A

Data model changes

  • N/A

Release notes snippet

  • Issue #3298289 β†’ : Fixed the problem with multiple fields when at least one of them is disabled
πŸ› 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.71.5 2024