vail/static/ui.mjs

39 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-05-14 18:51:05 -06:00
/**
2022-05-15 10:46:51 -06:00
* Set up repeater autofill list, and make dropdown active
*
* This fills the dataset from the dropdown, and make each dropdown element set
* the value in the input field.
2022-05-14 18:51:05 -06:00
*/
2022-05-15 10:46:51 -06:00
function setRepeaterList() {
let input = document.querySelector("#repeater")
let datalist = document.querySelector("datalist#repeater-list")
let repeaterList = document.querySelector("#stock-repeaters .dropdown-content")
for (let a of repeaterList.children) {
if (a.tagName == "A") {
let opt = datalist.appendChild(document.createElement("option"))
if (a.dataset.value != undefined) {
opt.value = a.dataset.value
2022-05-14 18:51:05 -06:00
}
2022-05-15 10:46:51 -06:00
opt.textContent = a.textContent
a.addEventListener(
"click",
() => {
input.value = opt.value
input.dispatchEvent(new Event("change"))
},
)
}
2022-05-14 18:51:05 -06:00
}
}
function init() {
2022-05-15 10:46:51 -06:00
setRepeaterList()
2022-05-14 18:51:05 -06:00
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", init)
} else {
init()
}