Problem/Motivation

The widget throws when it is attached where jQuery UI never initialised the autocomplete on the input, as happens in a Linkit media library dialog. The line that overrides the resize of the suggestion list reaches into that data straight away:

this.jqObject.data(autocompleteDataKey) is undefined.

Steps to reproduce

  1. Put the Autocomplete Deluxe widget on a taxonomy reference field of a media type.
  2. Add media through the Linkit media library dialog in the editor, so the widget is attached inside that dialog.
  3. The dialog stops with the error above and the field is not built.

Proposed resolution

Only override the resize when the autocomplete really is there, so the widget stops throwing where it cannot take that step.

The widget working on a field of its own after the guard

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
  • ➖ Developer Documentation
  • ➖ User Guide Documentation
  • ➖ Reviewed by human
  • ➖ Code review by maintainers
  • ➖ Full testing and approval
  • ➖ Credit contributors
  • ➖ Review with the product owner
  • ➖ Release notes snippet
  • ❌ Release

User interface changes

  • N/A

API changes

  • N/A

Data model changes

  • N/A

Release notes snippet

  • The widget no longer throws where jQuery UI did not initialise the autocomplete on the input.
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

sleepingmonk created an issue. See original summary.

sleepingmonk’s picture

rajab natshah’s picture

Version: 2.0.x-dev » 2.1.x-dev
Assigned: Unassigned » rajab natshah
Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new66.61 KB
new704 bytes

Thank you, Calvin for reporting, and for pinning it to that line.

Reproduced the failing shape on a fresh Drupal 11.4 site with only this module and a field of its own: reaching into the autocomplete data of an input that jQuery UI never initialised throws TypeError: Cannot set properties of undefined (setting '_resizeMenu'), which is the error you saw in the dialog.

The patch guards that one line. On the same site the ordinary field is unchanged: the data is there, the resize override is still applied, the suggestion list opens, a tag is added and the node saves.

Attaching it as a patch rather than a merge request, since the issue fork could not be created just now. Happy to move it to a merge request afterwards.

The widget working on a field of its own after the guard

To review, test, then merge.

rajab natshah’s picture

Thank you Calvin for reporting this, and for pinning it to the line.

I have opened a merge request against 2.1.x. The widget was reaching into the autocomplete data of the input and setting _resizeMenu on it without checking that jQuery UI had ever initialized an autocomplete there. Where it had not, that line threw. It is now skipped when there is nothing to override, and the suggestion list simply resizes the way jQuery UI wants to, which is a much better outcome than the widget falling over.

I should be straight about one thing: the Linkit media library dialog no longer fails on 2.1.x with Drupal 11.4. I set it up on a fresh 11.4.5 site with Linkit, Media and Media Library, put the widget on the media library form display, and everything initialized cleanly with no console errors. Current Drupal gives elements rendered over AJAX a random suffix on their ID, which quietly removed the duplicate ID collision that caused your original report.

The line is still worth guarding, though. Reaching into the autocomplete data of an input that jQuery UI never touched throws exactly the error you saw, and I confirmed that in the console on that same site. So this goes in as hardening rather than as a fix for your scenario, and the merge request says so plainly.

With the guard in place I added a tag inside the dialog and saved the media, and the term was stored correctly with no duplicate created.

There is no automated test, on purpose. The situation the guard protects against cannot be reached through the interface on any supported Drupal, so a browser test would pass whether or not the fix were there and would prove nothing. Testing it properly would need a JavaScript unit test harness, which this project does not have yet and which deserves an issue of its own.

One thing I noticed while in there, worth its own issue: MultipleWidget() is handed the input element as its first argument and never uses it, resolving the element with a document-wide ID lookup instead. That lookup is the real reason the widget can ever end up attached to the wrong node.

Prepared with AI assistance (Claude), reviewed and driven by the maintainer.

  • rajab natshah committed 9d4ca93c on 2.1.x
    fix: #3284962 Skip the resize override where jQuery UI did not...
rajab natshah’s picture

Assigned: rajab natshah » Unassigned
Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.