shift73k/assets_old/js/_form-validity.js

18 lines
481 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
);
});