Problem/motivation

In this scenario:

  • Content type with two link fields, Field A and Field B
  • Field A configured to NOT allow link text; Uses LinkIt field widget
  • Field B configured with OPTIONAL link text; Uses LinkIt field with "auto populate link text" checked

Then Field A's widget becomes broken. The autocomplete dropdown shows, but clicking an item from it does nothing. It doesn't populate the input with the value from the dropdown.

This is similar to #3358023: When multiple Link fields are present and set to "automatically populate", link title values in other fields can be overwritten but the fix there didn't go far enough to resolve this scenario.

Steps to reproduce

See above

Proposed resolution

The autocomplete JS needs to be updated. The logic in it for determining if auto populate of link text is enabled for the field widget isn't scoped properly.

This module uses Gitlab CI for automated testing of proposed code changes. To contribute code changes, create a merge request. Patch files will not trigger automated testing and are not sufficient for review.

Issue fork linkit-3538856

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

bkosborne created an issue. See original summary.

bkosborne’s picture

Issue summary: View changes
bkosborne’s picture

I marked #3447685: Linkit field doesn't work in nested Paragraph when Auto populate link text is enabled as a duplicate of this.

Maintainers, please add users "mahde" and "deulenko" to issue credits.

bkosborne’s picture

Status: Active » Needs review

Okay, I refactored the logic here to be more precise in finding the correct title field to manipulate and to fix things so that if a title field cannot be found, the basic functionality of the selection handler (populating the uri input field with the clicked autocomplete value) still works.

Note that the logic for assigning $context variable is flawed as it doesn't scope correctly when there's no fieldset wrapping the link field (there won't be if the link field doesn't have a title field output).
const $context = $(event.target).closest('form,fieldset,tr');

But as far as I can tell, it's not that important and affects only people using LinkIt with CKE4. Given that's deprecated I think it's best not to touch it.

mark_fullmer’s picture

mark_fullmer’s picture

mark_fullmer’s picture

Status: Needs review » Fixed

But as far as I can tell, it's not that important and affects only people using LinkIt with CKE4. Given that's deprecated I think it's best not to touch it.

Okay, thanks for the clarification. I agree with the rationale to leave it alone.

Maintainers, please add users "mahde" and "deulenko" to issue credits.

Done. Thanks for being conscientious!

bkosborne’s picture

Thank you!

Status: Fixed » Closed (fixed)

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