xhrform: use client-side field validation for forms if possible - jscancer - Ja… | |
git clone git://git.codemadness.org/jscancer | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit d606fe0157d28f240efac38511c881e6e781ce68 | |
parent 332824c6a39d3582747c7c10ea1e6ba5920a3ae9 | |
Author: Hiltjo Posthuma <[email protected]> | |
Date: Thu, 15 Dec 2022 19:20:14 +0100 | |
xhrform: use client-side field validation for forms if possible | |
these are attributes like "required" or "pattern". | |
Diffstat: | |
M xhrform/xhrform.js | 3 ++- | |
1 file changed, 2 insertions(+), 1 deletion(-) | |
--- | |
diff --git a/xhrform/xhrform.js b/xhrform/xhrform.js | |
@@ -48,7 +48,8 @@ document.addEventListener("click", function(e) { | |
!e.target.form || e.target.getAttribute("data-xhr") === null) | |
return; | |
- xhr_form_submit(e.target); | |
+ if (!e.target.form.reportValidity || e.target.form.reportValidity()) | |
+ xhr_form_submit(e.target); | |
// prevent default action. | |
e.preventDefault(); |