Abstract JS for multivalue form fields

This commit is contained in:
Chad Nelson
2021-11-21 17:18:18 -05:00
parent 8a6f78cfff
commit 6be9ac4f70
3 changed files with 29 additions and 5 deletions

View File

@ -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)
}
}();