shift73k/assets/js/_form-validity.js

19 lines
480 B
JavaScript
Raw Normal View History

// Fetch all the forms we want to apply custom Bootstrap validation styles to
let forms = document.querySelectorAll(".needs-validation");
// Loop over them and prevent submission
Array.prototype.slice.call(forms).forEach(function (form) {
form.addEventListener(
"submit",
function (event) {
if (!form.checkValidity()) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add("was-validated");
},
false
);
});