Skip to content

Commit

Permalink
Improve errors on signup form validation
Browse files Browse the repository at this point in the history
  • Loading branch information
paty-oliveira committed Aug 8, 2023
1 parent 6881b21 commit 1db76f7
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,27 @@ let resetMessage = () => {
document.getElementById("empty-error-message").hidden = true;
};

let isNewEmail = (email) => {
return usersTable.filter((user) => user.username === email).length === 0;
};

let isEmptyEmail = (email) => {
return email.length === 0;
};

addEventListener("submit", (event) => {
event.preventDefault();
resetMessage();

let email = document.getElementById("email").value;

// TODO: Show Correct Status Messages on Signup Form
// 1. successful signup
// 2. empty email
// 3. taken email
// 4. repeat email
if (isEmptyEmail(email)) {
renderEmailEmptyError();
} else if (isNewEmail(email)) {
renderSuccess();
} else {
renderEmailTakenError();
}
});

let toggleNav = () => {
Expand Down

0 comments on commit 1db76f7

Please sign in to comment.