reset button empties

This commit is contained in:
Christoph J. Scherr 2023-10-07 19:34:13 +02:00
parent 21f3b19111
commit 260005dcf0
1 changed files with 25 additions and 4 deletions

View File

@ -3,14 +3,14 @@
const setTheme = (theme) => { const setTheme = (theme) => {
document.documentElement.setAttribute("data-bs-theme", theme); document.documentElement.setAttribute("data-bs-theme", theme);
if (theme === "dark") { if (theme === "dark") {
var to_invert = document.querySelectorAll('.darkmode-invert'); var to_invert = document.querySelectorAll(".darkmode-invert");
to_invert.forEach(element => { to_invert.forEach((element) => {
element.style.filter = "invert(100%)"; element.style.filter = "invert(100%)";
}); });
} }
if (theme === "light") { if (theme === "light") {
var to_invert = document.querySelectorAll('.darkmode-invert'); var to_invert = document.querySelectorAll(".darkmode-invert");
to_invert.forEach(element => { to_invert.forEach((element) => {
element.style.filter = "invert(0%)"; element.style.filter = "invert(0%)";
}); });
} }
@ -37,3 +37,24 @@ document.getElementById("toggleThemeButton").onclick = function () {
function get_current_lang() { function get_current_lang() {
return location.pathname.split("/")[1]; return location.pathname.split("/")[1];
} }
// reset some forms to empty instead of the defaults in value attrs
document.querySelectorAll(".reset-empty-button").forEach((element) => {
element.onclick = function () {
var items = element.form.querySelectorAll("input, select, .tagify");
items.forEach((element) => {
if (element.type === "reset") {
} else {
if (element instanceof HTMLInputElement) {
element.setAttribute("value", element.getAttribute("defaultValue"));
} else if (element instanceof HTMLSelectElement) {
element.options
.item(element.selectedIndex)
.removeAttribute("selected");
element.options.item(0).setAttribute("selected", "");
}
}
});
element.form.reset();
};
});