mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-23 01:06:22 +00:00
30 lines
818 B
JavaScript
30 lines
818 B
JavaScript
|
import { Controller } from "stimulus";
|
||
|
|
||
|
export default class extends Controller {
|
||
|
connect() {
|
||
|
this.element.setAttribute("novalidate", true);
|
||
|
|
||
|
for (const input of this.element.elements) {
|
||
|
if (input.type === "button" || input.type === "submit") continue;
|
||
|
|
||
|
if (input.dataset.action) {
|
||
|
input.dataset.action = `${input.dataset.action} htmx:validation:validate->form-validation#submit`;
|
||
|
} else {
|
||
|
input.dataset.action = "htmx:validation:validate->form-validation#submit";
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
submit(event = undefined) {
|
||
|
event?.preventDefault();
|
||
|
event?.stopPropagation();
|
||
|
|
||
|
if (this.element.reportValidity()) {
|
||
|
this.element.classList.remove("was-validated");
|
||
|
this.element.submit();
|
||
|
} else {
|
||
|
this.element.classList.add("was-validated");
|
||
|
}
|
||
|
}
|
||
|
}
|