const enableValidation = () => {
// It will find all forms with the specified class in DOM, and
// make an array from them using the Array.from() method
const formList = Array.from(document.querySelectorAll(".form"));
// Iterate over the resulting array
formList.forEach((formElement) => {
formElement.addEventListener("submit", (evt) => {
// Cancel default behavior for each form
evt.preventDefault();
});
// Call the setEventListeners() function for each form,
// taking a form element as an argument
setEventListeners(formElement);
});
};
// Call the function
enableValidation();
const setEventListeners = (formElement) => {
const inputList = Array.from(formElement.querySelectorAll(".form__input"));
inputList.forEach((inputElement) => {
inputElement.addEventListener("input", function () {
checkInputValidity(formElement, inputElement);
});
});
};
const enableValidation = () => {
const formList = Array.from(document.querySelectorAll(".form"));
formList.forEach((formElement) => {
formElement.addEventListener("submit", (evt) => {
evt.preventDefault();
});
setEventListeners(formElement);
});
};
// Call the function
enableValidation();