When using this Form element in Ajax context like on Entity Reference Layout with layout_options the default value is lost.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | trigger_element_submit.png | 11.72 KB | zanvidmar |
| #4 | check_for_remove_btn-3102729-4.patch | 561 bytes | zanvidmar |
| #2 | check_for_remove_btn-3102729-2.patch | 627 bytes | tom robert |
Comments
Comment #2
tom robert commentedAdded an extra to check to verify that the the remove button is clicked when setting the value to NULL.
Comment #3
nightlife2008 commentedThanks 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
Comment #4
zanvidmar commentedSince 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.

Comment #5
zanvidmar commentedComment #6
bgreco commentedAfter 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.
Comment #7
maskedjellybean#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.
Comment #9
nightlife2008 commentedI have merged the patch and created a new release: alpha8.
Thanks all!