collections

This commit is contained in:
Benjamin Dalsass
2025-12-03 17:47:22 +01:00
parent b1129f19d7
commit 4620710f5a
8 changed files with 60 additions and 40 deletions

View File

@@ -0,0 +1,34 @@
class CollectionElement extends HTMLElement {
#eBtn;
// register the custom element
static {
customElements.define('collection-element', CollectionElement);
}
static addFormToCollection(e) {
const collectionHolder = document.querySelector('.'+e.currentTarget.dataset.collectionHolderClass);
const item = document.createElement('div');
item.style.marginTop = '20px';
item.innerHTML = collectionHolder
.dataset
.prototype
.replace(
/__name__/g,
collectionHolder.dataset.index
);
collectionHolder.appendChild(item);
collectionHolder.dataset.index++;
console.log(collectionHolder.dataset.index);
}
/** connectedCallback **/
connectedCallback() {
this.#eBtn = this.querySelector('.add_item_link');
this.#eBtn.addEventListener('click', CollectionElement.addFormToCollection);
}
}