Autocomplete changes the data-autocomplete-path to the default value when validating the node

Created on 11 August 2023, over 1 year ago
Updated 22 February 2024, 10 months ago

Problem/Motivation

For example, I have a dynamic_entity_reference with two entity types - user and group. When I save the node and it does not pass validation, the value in the select list is saved, but the value of data-autocomplete-path is changed to the default, which leads to a lack of synchronisation between the select list and autocomplete. This works well when you change the value in the select list twice, then the change event in the js code is fired and these fields are synchronized well.

Look at the screenshot, User is selected in the select list, but autocomplete pulls up the group entities.

Steps to reproduce

1) Create a dynamic_entity_reference field with two entity types, for example - User and Group. Also in the settings of the field, set Group as the default value
2) Add this field to manage_form_display for some content type, and go to the node creation form
3) Activate User in the select list and select a specific user in the autocomplete field
4) Leave a mistake when creating the form so that the form does not pass validation (for example, do not fill in a required field)
5) After the node fails validation, go back to the field and try to change the user in autocomplete. You'll see that autocomplete gives you only group options, not user options. Although the User is activated in the select list

Proposed resolution

The js file dynamic-entity-reference-widget.js is responsible for the widget logic. There is an EventListener "change" that executes the logic every time the list selector changes. But there is a problem when the page is reloaded (in our case, the node does not pass validation, when you click save, the page reloads) - autocomplete changes the data-autocomplete-path to the default (in our case, to the group), but User is selected in the select list.
So, you need to execute the same code when the page has loaded. To synchronize autocomplete with the select list

πŸ› Bug report
Status

Needs review

Version

1.16

Component

User interface

Created by

πŸ‡ΊπŸ‡¦Ukraine v.koval

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024