Problem/Motivation
Uncaught TypeError: Cannot read properties of undefined (reading 'replace') gets thrown when titleSelector (or linkSelector) in linkit.autocomplete.js is undefined and the code only looks for null.
The selected item does not populate the field.
This was not an issue in 6.0.0-rc1.
Steps to reproduce
Add LinkIt widget to a field. Do not enable "Automatically populate link text from entity label" (the default).
Search for something that returns matches, click one of them.
Because LinkitWidget's linkit_auto_link_text setting was FALSE the attribute data-linkit-widget-title-autofill-enabled is not added to the input and the script gets an empty jQuery collection in $linkTitle and $linkTitle.attr('data-drupal-selector') returns undefined.
Proposed resolution
Move everything related to linkSelector and titleSelector inside the check if ($linkTitle.length > 0) { and check for undefined instead of null in the moved statements.
Remaining tasks
Implement.
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 3370977-6.0.x-3.patch | 1.34 KB | mark_fullmer |
| #3 | 3370977-6.1.x-3.patch | 1.34 KB | mark_fullmer |
Comments
Comment #2
mark_fullmerThis was presumably introduced in #3358023: When multiple Link fields are present and set to "automatically populate", link title values in other fields can be overwritten, since that's the only change to the autocomplete JS since 6.0.0-rc1 that is currently 6.0.x. Thanks for reporting and for the steps to reproduce and logical suggestion for remediation. I should be able to address this in the next few days.
Comment #3
mark_fullmerPatches for 6.0.x and 6.1.x attached, implementing the proposed resolution.
Comment #5
mark_fullmerThe failing test in 6.1.x is unrelated and will be resolved in #3362578: Fix failing 6.1.x test.
Comment #8
mark_fullmerComment #9
twodThanks! Looks good to me and very similar to what I tested locally before reverting to the release.