Linkit field doesn't work in nested Paragraph when Auto populate link text is enabled

Created on 16 May 2024, 4 months ago
Updated 12 July 2024, about 2 months ago

Problem/motivation

When I have a link field with linkit widget in a paragraph reference field and this paragraph is a nested inside another paragraph reference field, when I enable Automatically populate link text from entity label then the link field doesn't function and when I select a link it doesn't insert the value inside the field and also doesn't fill the link text field.
also sometimes I get this error in the console, I am not sure if it's related:

Pattern attribute value \<front\>|\/.*|\?.*|#.*|[hH][tT][Tt][pP][sS]?://.+|.*\(\d+\) is not a valid regular expression: Uncaught SyntaxError: Invalid regular expression: /\<front\>|\/.*|\?.*|#.*|[hH][tT][Tt][pP][sS]?://.+|.*\(\d+\)/v: Invalid escape

Steps to reproduce

  1. Create a content type
  2. Create two paragraph types, let's say Paragraph 1 and Paragraph 2
  3. Create a paragraph reference field in the content type and reference Paragraph 1
  4. Now inside Paragraph 1 create a paragraph reference field and reference Paragraph 2
  5. Then inside Paragraph 2, create a link field and in the manage form display choose Linkit widget and enable Automatically populate link text from entity label
  6. Now you will see the problem
πŸ› Bug report
Status

Active

Version

7.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada mahde Vancouver

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

Comments & Activities

  • Issue created by @mahde
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson
  • πŸ‡¨πŸ‡¦Canada mahde Vancouver

    The actual issue was that the field title has the word "title" in it and I found that there is a statement in the linkit.autocomplete.js file:

    if (titleSelector.replace('-title', '') !== linkSelector.replace('-uri', '')) {
      return false;
    }

    Which is replacing the '-title' and because my field has '-title' so it's replacing the first string found and therefore the statement is false and autocomplete will stop working.

    I added a new function to replace only the last occurrence for '-title' to avoid this problem and now it works.
    Hope to add this fix to the module to avoid this issue when any field has 'title' string in the label.

Production build 0.71.5 2024