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.

Comments

TwoD created an issue. See original summary.

mark_fullmer’s picture

Assigned: Unassigned » mark_fullmer

This 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.

mark_fullmer’s picture

Status: Active » Needs review
StatusFileSize
new1.34 KB
new1.34 KB

Patches for 6.0.x and 6.1.x attached, implementing the proposed resolution.

The last submitted patch, 3: 3370977-6.1.x-3.patch, failed testing. View results

mark_fullmer’s picture

The failing test in 6.1.x is unrelated and will be resolved in #3362578: Fix failing 6.1.x test.

  • mark_fullmer committed 4167d74c on 6.0.x
    Issue #3370977 by mark_fullmer, TwoD: JavaScript error when title...

  • mark_fullmer committed e7ef8dac on 6.1.x
    Issue #3370977 by mark_fullmer, TwoD: JavaScript error when title...
mark_fullmer’s picture

Status: Needs review » Fixed
twod’s picture

Thanks! Looks good to me and very similar to what I tested locally before reverting to the release.

Status: Fixed » Closed (fixed)

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