website/web/static/js/slim-forms.js

18 lines
592 B
JavaScript
Raw Normal View History

2024-06-27 04:27:03 +00:00
/* Slim "GET" forms: an onSubmit handler that trims empty query parameters. */
document.addEventListener('DOMContentLoaded', (e) => {
(document.querySelectorAll("form") || []).forEach(form => {
// Find forms with method="GET"
let method = form.method || "GET";
if (method.toUpperCase() !== "GET") {
return;
};
// Trim their empty parameters.
form.addEventListener("submit", (e) => {
for (let member of form.elements) {
if (!member.value) member.disabled = true;
}
})
});
});