adding cancelable custom event on item removal
This commit is contained in:
parent
73cbd36cd1
commit
1aa62b036f
2 changed files with 14 additions and 4 deletions
|
@ -15,16 +15,26 @@ 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())
|
||||
}
|
||||
if (element.dispatchEvent(new CustomEvent(
|
||||
'beforeStampRemoval',
|
||||
{
|
||||
cancelable: true,
|
||||
detail: {
|
||||
toBeRemoved: rowToDelete
|
||||
}
|
||||
}
|
||||
))) {
|
||||
rowToDelete.remove();
|
||||
}
|
||||
}
|
||||
|
||||
element.addEventListener('click', () => {
|
||||
const clone = template.content.cloneNode(true);
|
||||
|
|
|
@ -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": {
|
||||
|
|
Loading…
Reference in a new issue