Problem/Motivation

If a user has selected an item from the DER widget autocomplete dropdown and then subsequently changes the entity type selected, the previously selected entity will now be invalid and will throw an error if the user then tries to submit the form. Obviously there's an easy workaround to manually clear the field value but it would be fairly easy to clear it via JS on change.

Proposed resolution

Enhance the dynamicEntityReferenceWidgetSelect JS function to clear the autocomplete field.

Remaining tasks

Tests
Code

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

acbramley created an issue. See original summary.

jibran’s picture

Category: Feature request » Bug report
Priority: Minor » Normal

I think it is a bug.

acbramley’s picture

Assigned: Unassigned » acbramley

Working on this today.

acbramley’s picture

Status: Active » Needs review
FileSize
3.68 KB

Here's a failing test. I couldn't get the tests to work without selecting the autocomplete option. It's something to do with the dropdown not disappearing when selecting the new entity type. Even with $autocomplete_field->keyDown(self::ESCAPE_KEY); it wasn't dropping off.

acbramley’s picture

The last submitted patch, 4: 2906492-4-failing-test.patch, failed testing. View results

fenstrat’s picture

Nice one, LGTM.

+++ b/tests/src/FunctionalJavascript/DynamicEntityReferenceTest.php
@@ -278,4 +264,38 @@ class DynamicEntityReferenceTest extends JavascriptTestBase {
+    sleep(1);

Assuming things fail without this?

acbramley’s picture

fenstrat’s picture

Status: Needs review » Reviewed & tested by the community

Great!

  • jibran committed 5595d72 on 8.x-1.x authored by acbramley
    Issue #2906492 by acbramley, fenstrat: Clear Label field in widget when...

  • jibran committed 20339b4 on 8.x-2.x authored by acbramley
    Issue #2906492 by acbramley, fenstrat: Clear Label field in widget when...
jibran’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, committed and pushed to both branches.

Status: Fixed » Closed (fixed)

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