EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

Add collection reference to 'ea.collection.item-added' and "ea.collection.item-removed" events

Open nevez opened this issue 1 year ago • 0 comments

It would be helpful to have the collection tag available as detail of the events "ea.collection.item-added" and "ea.collection.item-removed" events, otherwise there is no simple way to know which add or trash button was pressed, if there is more than 1 collection field in the page.

It's a matter of changing these two lines in field-collection.js.

Line 19 document.dispatchEvent(new Event('ea.collection.item-removed'));

Line 70 document.dispatchEvent(new Event('ea.collection.item-added'));

You can use new CustomEvent(, { detail : }) instead of new Event(), or fire the event on the collection tag (instead of the document) and set { bubbles: true } to make it bubble up to the document. The latter is probably a better option, although a bit slower.

The rest of EasyAdmin code is unaffected.

MDN

nevez avatar Nov 27 '23 10:11 nevez