Abstract JS for multivalue form fields
This commit is contained in:
@ -368,4 +368,22 @@ let BookWyrm = new class {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
duplicateInput (input_id ) {
|
||||
const orig = document.getElementById(input_id);
|
||||
const parent = orig.parentNode;
|
||||
const new_count = parent.querySelectorAll("input").length + 1
|
||||
|
||||
let input = orig.cloneNode();
|
||||
|
||||
input.id += ("-" + (new_count))
|
||||
input.value = ""
|
||||
|
||||
let label = parent.querySelector("label").cloneNode();
|
||||
|
||||
label.setAttribute("for", input.id)
|
||||
|
||||
parent.appendChild(label)
|
||||
parent.appendChild(input)
|
||||
}
|
||||
}();
|
||||
|
Reference in New Issue
Block a user