When using this Form element in Ajax context like on Entity Reference Layout with layout_options the default value is lost.

Comments

Tom Robert created an issue. See original summary.

tom robert’s picture

StatusFileSize
new627 bytes

Added an extra to check to verify that the the remove button is clicked when setting the value to NULL.

nightlife2008’s picture

Thanks for the issue report and according patch.

I am not sure though if checking if a CSS class exists is the optimal approach to tackle this.

We should inspect the triggeringElement to see if we can derive the action from the #op property or something else.

I'm going into christmas holiday 'till the second of 2020 so this will be on hold until then.

Greets,
Kim

zanvidmar’s picture

StatusFileSize
new561 bytes
new11.72 KB

Since 8.x-1.0-alpha7 this patch from #2 does not work anymore.
I created new patch that is checking the same thing (check to verify that the the remove button is clicked ) but I did it via trigger element last parent machine name which is in this case "remove_button".

Alternatively, it would be also possible to check the '#submit' value from trigger element to check if submission is related to "removeItem" method, but I am not sure if this has any advatages over what I wrote above.
submit element

zanvidmar’s picture

Status: Active » Needs review
bgreco’s picture

After upgrading from 1.0-alpha4 to 1.0-alpha7, I found that if the form element has a #default_value, the "Remove" button no longer works even in standard forms (I haven't tested an ajax form). The patch from #4 fixes this issue as well.

maskedjellybean’s picture

#4 resolved the issue I was having after programmatically adding a Media Library field to the section configuration form of Layout Builder. I could add a media item but I couldn't remove it. After this patch I can add and remove.

  • a6c8178 committed on 8.x-1.x
    Issue #3102729: Default settings are lost in Ajax context
    
  • d653f8e committed on 8.x-1.x
    Issue #3102729: Allow multiple values to be selected
    
nightlife2008’s picture

Status: Needs review » Fixed

I have merged the patch and created a new release: alpha8.

Thanks all!

Status: Fixed » Closed (fixed)

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