18 lines
592 B
JavaScript
18 lines
592 B
JavaScript
|
/* 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;
|
||
|
}
|
||
|
})
|
||
|
});
|
||
|
});
|