fix: #3284962 Skip the resize override where jQuery UI did not initialize

Fixes the crash reported in #3284962.

What this changes

MultipleWidget.setup() reached into jqObject.data(autocompleteDataKey) and set _resizeMenu on it without checking that jQuery UI had initialized the autocomplete on that input. Where it had not, the statement threw:

TypeError: Cannot set properties of undefined (setting '_resizeMenu')

The override is now skipped when there is no autocomplete instance. The suggestion list then resizes as jQuery UI sees fit, which is better than throwing.

Honest note on the reported scenario

The original report is a Linkit media library dialog. That path no longer reproduces on 2.1.x with Drupal 11.4. Verified on a fresh 11.4.5 site with linkit 7.0.16, media and media_library, with the widget on the media.image.media_library form display and a media_library_widget field on the node form:

input in dialog ui-autocomplete data widget attached
autocomplete-deluxe-input no yes yes
autocomplete-deluxe-input--jqIQUOrAPTc yes yes yes

Zero console errors. Current core gives AJAX-rendered elements a random id suffix, which removes the duplicate-id collision that produced the original failure.

The guarded line is still worth fixing: reaching into the autocomplete data of an input jQuery UI never initialized throws the exact reported TypeError, confirmed in the live console on that same site. So this lands as hardening, not as a claimed fix of the reporter's scenario.

Follow-up worth its own issue

MultipleWidget(input, settings) takes input as its first argument and never uses it. init() instead resolves the element with a document-wide $('#' + settings.input_id) lookup, which is the mechanism that can leave jqObject empty or bound to the wrong node when ids collide. Binding to the passed input is the real fix, but it is a behavioural change with a wider blast radius than this issue.

On automated test coverage

This guard is not covered by an automated test, deliberately.

The condition it guards is "jQuery UI never initialized the autocomplete on this input". On supported core that condition is not reachable through the UI - the media library dialog initializes the widget correctly, which is the same reason the original bug stopped reproducing. A .feature file driving the dialog passes identically with and without this change, so it would assert nothing about the fix.

Covering it properly means unit testing MultipleWidget.setup() against a stub input, and the project has no JavaScript unit test runner (no jest/vitest/mocha in package.json; the only PHP test is tests/src/Unit/ThemeStylingLibrariesTest.php). Introducing that harness is worth its own issue rather than being folded into a four line defensive fix.

Checkpoints

  • File an issue about this project
  • Addition/Change/Update/Fix to this project
  • Testing to ensure no regression
  • Automated unit/functional testing coverage
  • Developer Documentation support on feature change/addition
  • User Guide Documentation support on feature change/addition
  • UX/UI designer responsibilities
  • Accessibility and Readability
  • Reviewed by a human
  • Code review by maintainers
  • Full testing and approval
  • Credit contributors
  • Review with the product owner
  • Update Release Notes
  • Release

AI-Generated: Yes (guard on the resize override, and the investigation behind it; reviewed by rajab natshah.)

Edited by Rajab Natshah

Merge request reports

Loading
Loading