diff --git a/form-stamp.js b/form-stamp.js index 481d737..34d1992 100644 --- a/form-stamp.js +++ b/form-stamp.js @@ -15,15 +15,25 @@ export function formStamp(element, options = {}) const itemSelector = '.' + template.content.firstElementChild.className.replace(/ /g, '.'); const initialItemCount = container.querySelectorAll(itemSelector).length; let created = 0; - const removeRow = (element) => () => { - const rowToDelete = element.closest(itemSelector); + const removeRow = (removeItem) => () => { + const rowToDelete = removeItem.closest(itemSelector); // Flow renders identity fields directly at the form tag, so we need to look if (rowToDelete.dataset.stampRemoveWithMe) { container.closest('form') .querySelectorAll(rowToDelete.dataset.stampRemoveWithMe) .forEach(child => child.remove()) } - rowToDelete.remove(); + if (element.dispatchEvent(new CustomEvent( + 'beforeStampRemoval', + { + cancelable: true, + detail: { + toBeRemoved: rowToDelete + } + } + ))) { + rowToDelete.remove(); + } } element.addEventListener('click', () => { diff --git a/package.json b/package.json index 6b5727e..8c44091 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@digicomp/form-stamp", - "version": "0.0.2", + "version": "0.0.3", "description": "duplicates an entry form field group", "main": "form-stamp.js", "scripts": {