internet-programming/lab3/js/validation.js
2024-01-12 14:27:01 +04:00

16 lines
459 B
JavaScript

function validation() {
const forms = document.querySelectorAll("form.needs-validation");
for (let i = 0; i < forms.length; i += 1) {
const form = forms[i];
form.addEventListener("submit", (event) => {
if (!form.checkValidity()) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add("was-validated");
});
}
}
export default validation;