Compare commits

..

No commits in common. "main" and "0.0.4" have entirely different histories.
main ... 0.0.4

2 changed files with 6 additions and 8 deletions

View file

@ -1,21 +1,19 @@
/* jshint esversion: 6 */
const defaults = {
nameToReplace: 'idx',
removeSelector: '.remove',
minimalId: 'auto'
removeSelector: '.remove'
}
export function formStamp(element, options = {})
{
const {
nameToReplace,
removeSelector,
minimalId
removeSelector
} = { ...defaults, ...element.dataset, ...options };
const container = element.parentElement;
const template = element.querySelector('template');
const itemSelector = '.' + template.content.firstElementChild.className.replace(/ /g, '.');
const startWithId = minimalId === 'auto' ? container.querySelectorAll(itemSelector).length : parseInt(minimalId);
const initialItemCount = container.querySelectorAll(itemSelector).length;
let created = 0;
const afterDomManipulation = () => {
element.dispatchEvent(new CustomEvent('afterStampDomManipulation'));
@ -45,7 +43,7 @@ export function formStamp(element, options = {})
element.addEventListener('click', () => {
const clone = template.content.cloneNode(true);
clone.querySelectorAll('input, select, textarea').forEach(child => {
child.name = child.name.replace(nameToReplace, startWithId + created);
child.name = child.name.replace(nameToReplace, initialItemCount + created);
});
clone.querySelectorAll(removeSelector).forEach(child => {
child.onclick = removeRow(child);
@ -54,7 +52,7 @@ export function formStamp(element, options = {})
'beforeStampInsert',
{
detail: {
i: startWithId + created,
i: initialItemCount + created,
node: clone
},
cancelable: true

View file

@ -1,6 +1,6 @@
{
"name": "@digicomp/form-stamp",
"version": "0.0.5",
"version": "0.0.4",
"description": "duplicates an entry form field group",
"main": "form-stamp.js",
"scripts": {