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.
Issue fork linkit-3538856
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
Comment #2
bkosborneComment #3
bkosborneI 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.
Comment #5
bkosborneOkay, 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.
Comment #8
mark_fullmerComment #9
mark_fullmerComment #10
mark_fullmerOkay, thanks for the clarification. I agree with the rationale to leave it alone.
Done. Thanks for being conscientious!
Comment #12
bkosborneThank you!