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,15 +15,25 @@ export function formStamp(element, options = {})
|
||||||
const itemSelector = '.' + template.content.firstElementChild.className.replace(/ /g, '.');
|
const itemSelector = '.' + template.content.firstElementChild.className.replace(/ /g, '.');
|
||||||
const initialItemCount = container.querySelectorAll(itemSelector).length;
|
const initialItemCount = container.querySelectorAll(itemSelector).length;
|
||||||
let created = 0;
|
let created = 0;
|
||||||
const removeRow = (element) => () => {
|
const removeRow = (removeItem) => () => {
|
||||||
const rowToDelete = element.closest(itemSelector);
|
const rowToDelete = removeItem.closest(itemSelector);
|
||||||
// Flow renders identity fields directly at the form tag, so we need to look
|
// Flow renders identity fields directly at the form tag, so we need to look
|
||||||
if (rowToDelete.dataset.stampRemoveWithMe) {
|
if (rowToDelete.dataset.stampRemoveWithMe) {
|
||||||
container.closest('form')
|
container.closest('form')
|
||||||
.querySelectorAll(rowToDelete.dataset.stampRemoveWithMe)
|
.querySelectorAll(rowToDelete.dataset.stampRemoveWithMe)
|
||||||
.forEach(child => child.remove())
|
.forEach(child => child.remove())
|
||||||
}
|
}
|
||||||
rowToDelete.remove();
|
if (element.dispatchEvent(new CustomEvent(
|
||||||
|
'beforeStampRemoval',
|
||||||
|
{
|
||||||
|
cancelable: true,
|
||||||
|
detail: {
|
||||||
|
toBeRemoved: rowToDelete
|
||||||
|
}
|
||||||
|
}
|
||||||
|
))) {
|
||||||
|
rowToDelete.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
element.addEventListener('click', () => {
|
element.addEventListener('click', () => {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@digicomp/form-stamp",
|
"name": "@digicomp/form-stamp",
|
||||||
"version": "0.0.2",
|
"version": "0.0.3",
|
||||||
"description": "duplicates an entry form field group",
|
"description": "duplicates an entry form field group",
|
||||||
"main": "form-stamp.js",
|
"main": "form-stamp.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
Loading…
Reference in a new issue