mirror of
https://github.com/dzeiocom/FormManager.git
synced 2025-04-23 11:22:11 +00:00
parent
78a38edaeb
commit
2f91a15157
@ -12,7 +12,7 @@ export default class RepeatInput extends DefaultInput {
|
|||||||
|
|
||||||
elements: InputAbstract[][] = []
|
elements: InputAbstract[][] = []
|
||||||
|
|
||||||
private template: HTMLElement
|
private template: DocumentFragment
|
||||||
|
|
||||||
private addBtn: HTMLElement
|
private addBtn: HTMLElement
|
||||||
|
|
||||||
@ -20,14 +20,26 @@ export default class RepeatInput extends DefaultInput {
|
|||||||
super(element, form)
|
super(element, form)
|
||||||
|
|
||||||
//fetch Template
|
//fetch Template
|
||||||
this.template = element.querySelector(".fmr-template") as HTMLElement
|
let tmplEl = element.querySelector("template")
|
||||||
if (!this.template) throw Error(`Error: your repeat input "${this.getName()}" MUST have a child with the class .fmr-template`);
|
if (tmplEl) {
|
||||||
|
this.template = tmplEl.content
|
||||||
|
tmplEl.remove()
|
||||||
|
} else {
|
||||||
|
let el = element.querySelector(".fmr-template")
|
||||||
|
if (!el) {
|
||||||
|
throw Error("No Template or .fmr-template elements were found!")
|
||||||
|
}
|
||||||
|
el.classList.remove("fmr-template")
|
||||||
|
this.template = new DocumentFragment
|
||||||
|
this.template.appendChild(el.cloneNode(true))
|
||||||
|
el.remove()
|
||||||
|
}
|
||||||
|
|
||||||
this.template.style.display = "none"
|
if (!this.template) throw Error(`Your repeat input "${this.getName()}" MUST have a child with the class .fmr-template`);
|
||||||
|
|
||||||
//fetch add button
|
//fetch add button
|
||||||
this.addBtn = element.querySelector(".fmr-add") as HTMLElement
|
this.addBtn = element.querySelector(".fmr-add") as HTMLElement
|
||||||
if (!this.addBtn) throw Error(`Error: your repeat element "${this.getName()}" MUST have a child with the class .fmr-add`);
|
if (!this.addBtn) throw Error(`Your repeat element "${this.getName()}" MUST have a child with the class .fmr-add`);
|
||||||
|
|
||||||
this.addBtn.addEventListener("click", () => {
|
this.addBtn.addEventListener("click", () => {
|
||||||
if (!this.addBtn.hasAttribute("disabled")) this.addLine()
|
if (!this.addBtn.hasAttribute("disabled")) this.addLine()
|
||||||
@ -60,8 +72,10 @@ export default class RepeatInput extends DefaultInput {
|
|||||||
|
|
||||||
addLine(values?: any[]|any) {
|
addLine(values?: any[]|any) {
|
||||||
// the new line
|
// the new line
|
||||||
let node = this.element.insertBefore(this.template.cloneNode(true), this.addBtn) as HTMLElement
|
const clone = document.importNode(this.template, true)
|
||||||
node.classList.remove("fmr-template")
|
this.element.insertBefore(clone, this.addBtn)
|
||||||
|
let node = this.element.children.item(this.element.childElementCount-2) as HTMLElement
|
||||||
|
console.log(node)
|
||||||
node.classList.add("fmr-element")
|
node.classList.add("fmr-element")
|
||||||
node.style.display = ""
|
node.style.display = ""
|
||||||
|
|
||||||
@ -69,6 +83,7 @@ export default class RepeatInput extends DefaultInput {
|
|||||||
let sub: InputAbstract[] = [];
|
let sub: InputAbstract[] = [];
|
||||||
(node.querySelectorAll("[data-input]") as NodeListOf<HTMLElement>).forEach((el: HTMLElement) => {
|
(node.querySelectorAll("[data-input]") as NodeListOf<HTMLElement>).forEach((el: HTMLElement) => {
|
||||||
let input = this.form.getInit(el)
|
let input = this.form.getInit(el)
|
||||||
|
console.log(input, values)
|
||||||
if (!input) {
|
if (!input) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user