2024-07-05 12:38:45 +02:00
|
|
|
// SPDX-FileCopyrightText: 2024 Simon Bruder <simon@sbruder.de>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
|
|
|
(() => {
|
|
|
|
// Allows a form checkbox to toggle an input element.
|
|
|
|
// This requires the form to have a structure like described in the bootstrap documentation:
|
|
|
|
// https://getbootstrap.com/docs/5.3/forms/input-group/#checkboxes-and-radios
|
2024-07-11 22:56:22 +02:00
|
|
|
const inputToggle = target => {
|
|
|
|
target.parentElement.parentElement.querySelector("input:not(.input-toggle)").disabled = !target.checked
|
|
|
|
}
|
2024-07-05 12:38:45 +02:00
|
|
|
Array.from(document.getElementsByClassName("input-toggle")).forEach(el => {
|
2024-07-11 22:56:22 +02:00
|
|
|
inputToggle(el)
|
|
|
|
el.addEventListener("change", e => inputToggle(e.target))
|
2024-07-05 12:38:45 +02:00
|
|
|
})
|
2024-07-12 15:44:11 +02:00
|
|
|
|
|
|
|
const datalistHint = (input, hint) => {
|
|
|
|
const selected = input.list.querySelector(`option[value="${input.value}"]`);
|
|
|
|
if (selected === null)
|
|
|
|
hint.innerText = ""
|
|
|
|
else {
|
|
|
|
hint.innerHTML = selected.innerHTML
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Array.from(document.getElementsByClassName("datalist-hint")).forEach(hint => {
|
|
|
|
const input = hint.parentElement.querySelector("input[list]")
|
|
|
|
datalistHint(input, hint)
|
|
|
|
input.addEventListener("input", _ => datalistHint(input, hint))
|
|
|
|
})
|
2024-07-05 12:38:45 +02:00
|
|
|
})()
|