Skip to content

Commit

Permalink
refactor: formElements -> formInputs to be more precise
Browse files Browse the repository at this point in the history
  • Loading branch information
KpryKorn committed Feb 2, 2024
1 parent 8d6e5db commit 3ec4dea
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const closeConfirmationModalBtn = document.getElementById(
const submitBtn = document.getElementById("submitBtn");

/** ------------------------ FORM DATA VALUES ------------------------ **/
const formElements = {
const formInputs = {
firstName: document.getElementById("firstName"),
lastName: document.getElementById("lastName"),
email: document.getElementById("email"),
Expand All @@ -28,14 +28,14 @@ let formIsValid = false;

// TODO: logique à retravailler
function validateForm() {
// check tous les éléments de l'objet formElements et return true si tous les inputs sont pas vides
formIsValid = Object.values(formElements).every((element) => {
// check tous les inputs de l'objet et return true si tous les inputs sont pas vides
formIsValid = Object.values(formInputs).every((element) => {
if (element.value !== "") return true;
});
}

// check si le formulaire est valide à chaque onChange
Object.values(formElements).forEach((input) => {
Object.values(formInputs).forEach((input) => {
input.addEventListener("change", validateForm);
});

Expand Down

0 comments on commit 3ec4dea

Please sign in to comment.