mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-07-05 23:20:18 +02:00
22 lines
552 B
JavaScript
22 lines
552 B
JavaScript
import {Controller} from '@hotwired/stimulus';
|
|
|
|
export default class extends Controller {
|
|
static targets = ['collection'];
|
|
static values = {prototype: String};
|
|
|
|
connect() {
|
|
this.index = this.collectionTarget.children.length;
|
|
}
|
|
|
|
addItem() {
|
|
const item = document.createElement('div');
|
|
item.innerHTML = this.prototypeValue.replace(/__name__/g, this.index);
|
|
this.collectionTarget.appendChild(item.firstElementChild);
|
|
this.index++;
|
|
}
|
|
|
|
removeItem(event) {
|
|
event.target.closest('[data-collection-item]').remove();
|
|
}
|
|
}
|