Save field value even if suggestion not selected

Created on 26 September 2023, 9 months ago
Updated 1 October 2023, 9 months ago

Problem/Motivation

I have Linkit selected as widget for Link field and it always works correctly when the suggestion is clicked and used to select the wanted link target. However sometimes the content editors just want to paste in the target path or external URL and not to click on the suggestion. When this is done, the value seems to be saved at first but when returning to the edit view, the old value is back in the field.

Steps to reproduce

1) Configure a node link field to use Linkit widget
2) Create a node with an internal route on the link field
3) Open the node edit form. Type into the URL field an external route, such as "https://google.com" or some local path
4) Do not click on the dropdown suggestions. Instead click "Save" to save the node directly.
5) Check that field value seems to have changed first in the node view and then go back to node edit to see the old value back

Proposed resolution

I found that marcoscano already found this issue in the issue https://www.drupal.org/project/linkit/issues/2712951#comment-12605809 โœจ Linkit for Link field Fixed for adding Linkit support for fields. He first added a fix for it but then reverted it since he found some issues with it. I wasn't able to replicate his issues in the current module version.

๐Ÿ› Bug report
Status

Fixed

Version

6.0

Component

Code

Created by

๐Ÿ‡ซ๐Ÿ‡ฎFinland thatguy

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

Comments & Activities

  • Issue created by @thatguy
  • ๐Ÿ‡ซ๐Ÿ‡ฎFinland thatguy

    Here is a patch with marcoscanos fix from https://www.drupal.org/project/linkit/issues/2712951#comment-12605809 โœจ Linkit for Link field Fixed

  • Status changed to Needs review 9 months ago
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.0.7 + Environment: PHP 8.1 & MariaDB 10.3.22
    last update 9 months ago
    83 pass
  • ๐Ÿ‡ซ๐Ÿ‡ฎFinland thatguy
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mark_fullmer Tucson

    Setting this issue priority to "Major," since I consider this to be a significant user experience problem. Will review this soon.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States hawkeye.twolf Chattanooga, TN, USA

    hawkeye.twolf โ†’ made their first commit to this issueโ€™s fork.

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.0.7 + Environment: PHP 8.1 & MariaDB 10.3.22
    last update 9 months ago
    83 pass
  • @hawkeyetwolf opened merge request.
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States hawkeye.twolf Chattanooga, TN, USA

    MR !28 adds support for maintaining fragments and query strings (the issue that @marcoscano noted โœจ Linkit for Link field Fixed in the LinkIt for Fields issue).

  • ๐Ÿ‡ซ๐Ÿ‡ฎFinland thatguy

    MR !28 seems to fix the issue

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.0.7 + Environment: PHP 8.1 & MariaDB 10.3.22
    last update 9 months ago
    83 pass
  • Status changed to Postponed: needs info 9 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mark_fullmer Tucson

    MR !28 adds support for maintaining fragments and query strings (the issue that @marcoscano noted โœจ Linkit for Link field Fixed in the LinkIt for Fields issue).

    I'm unable to reproduce an issue specific to query parameters or anchor links that seems to necessitate the more substantial change proposed in MR !28.

    The less substantial change proposed in #2 seems to resolve all scenarios that I have tested. If there is a scenario that requires the more involved change proposed in the MR, can someone provide steps to reproduce?

    Here are the steps that I used to test #2 that demonstrate that the patch resolves the original problem:

    Scenario 1: Basic URL; Patch #2 passes

    1) Configure a node link field to use Linkit widget
    2) Create a node and set the link field to an internal route on the link field. After save, the link to the internal route will display correctly.
    3) Open the node edit form. Type into the URL field "https://google.com"
    4) Do not click on the dropdown suggestions. Instead click "Save" to save the node directly.
    5) Check that field value seems to have changed first in the node view and then go back to node edit to see the old value back.
    6) Go back to node edit and verify the value "https://google.com#test" is preserved.

    Scenario 2: URL with query parameter; Patch #2 passes

    1) Configure a node link field to use Linkit widget
    2) Create a node and set the link field to an internal route on the link field. After save, the link to the internal route will display correctly.
    3) Open the node edit form. Type into the URL field "https://google.com?test=1"
    4) Do not click on the dropdown suggestions. Instead click "Save" to save the node directly.
    5) Check that field value seems to have changed first in the node view and then go back to node edit to see the old value back.
    6) Go back to node edit and verify the value "https://google.com" is preserved.

    Scenario 3: URL with anchor link: Patch #2 passes

    1) Configure a node link field to use Linkit widget
    2) Create a node and set the link field to an internal route on the link field. After save, the link to the internal route will display correctly.
    3) Open the node edit form. Type into the URL field "https://google.com#test"
    4) Do not click on the dropdown suggestions. Instead click "Save" to save the node directly.
    5) Check that field value seems to have changed first in the node view and then go back to node edit to see the old value back.
    6) Go back to node edit and verify the value "https://google.com#test" is preserved.

    Scenario 4: URLs with differing queries: Patch #2 passes

    This scenario specifically tries to test the comment in MR 28:

    + // If any of the these properties differ between the two URLs, the
    + // hidden inputs storing options field data will be cleared.
    + // Essentially, we leave out any of the props that contain URL
    + // fragment (#) or query string (?). These include hash, href,
    + // search, and others.

    1) Configure a node link field to use Linkit widget
    2) Create a node and set the link field to an internal route on the link field. Append #foo to the internal route in the edit form. After save, the link to the internal route will display correctly, with the #foo anchor
    3) Open the node edit form. Type into the URL field "https://google.com#test"
    4) Do not click on the dropdown suggestions. Instead click "Save" to save the node directly.
    5) Check that field value seems to have changed first in the node view.
    6) Go back to node edit and verify the value "https://google.com#test" is preserved.

  • Status changed to Needs review 9 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States hawkeye.twolf Chattanooga, TN, USA

    Thank you for the review and thorough testing scenarios @mark_fullmer! ๐Ÿ™๐Ÿป๐Ÿ™๐Ÿป

    I think the bug @marcoscano referred to was with the clearing of match metadata stored in the link field's "options" array. I didn't actually test his patch until now, and found out it breaks a little worse than I thought. I expected:

    Match metadata gets saved if autocomplete dropdown is clicked, but cleared if the user "keyups" in the textfield.

    But it actually works like:*

    Hidden form inputs always get cleared, even when the autocomplete dropdown is used to click an entity matcher and the user has no direct interaction with the textbox.

    *Tested in Firefox on linux

    Specifically, the options data we lose with the first patch are:

    • data-entity-type
    • data-entity-uuid
    • data-entity-substitution

    The approach in MR 28 attempts to be less aggressive in clearing the match metadata. Specifically when any portion of the link changes, besides query string and fragment.

  • Status changed to Fixed 9 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mark_fullmer Tucson

    Thanks for clarifying, hawkeye.twolf! I understand how the patch in #2 is too aggressive. (The way I'd put it is: the hidden form inputs should not be cleared until a user either explicitly accepts the autocomplete suggestion or saves the form. Testing the MR with this in mind, it makes good sense to me.

    Merged into the 6.0.x and 6.1.x branches.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States hawkeye.twolf Chattanooga, TN, USA

    Great :D I see new releases already cutโ€”thanks so much @mark_fullmer!

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

Production build 0.69.0 2024