JavaScript error when title autofill is disabled

Created on 28 June 2023, over 1 year ago
Updated 29 June 2023, over 1 year ago

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.

πŸ› Bug report
Status

Fixed

Version

6.0

Component

Code

Created by

πŸ‡ΈπŸ‡ͺSweden twod Sweden

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024