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

Created on 16 May 2024, over 1 year 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

6.1

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada mahde Vancouver

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

Merge Requests

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.

  • πŸ‡ΊπŸ‡¦Ukraine deulenko

    I encountered the same issue on Drupal 10.4.6, but the existing patch doesn’t appear to work with this version. I’ve attached a new patch that ensures compatibility with Drupal 10.

  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    I've converted the patch to a merge request so we can see what this does in automated test coverage. On the surface, the changes involved here look like they could have unintentional side effects.

  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

    I'm confused about the patch in #4 as it is completely different from the patch in #3.

    It sounds like the root of this problem is that the logic for finding the title field is flawed. There's other issues with this logic too that I discovered in πŸ› Field widget broken if there's multiple link fields, one without link text enabled Active . I created an MR in there to cover those issues as well as the issue here. I think this can be closed as a duplicate of that (I realize this issue was open first, but I'm not sure what's going on with the MR/patch here, and my issue covers additional issues. I'll carry over the issue credits to that one).

Production build 0.71.5 2024