Skip to content

Commit

Permalink
Validate sign up form elements on page reload (publiclab#8506)
Browse files Browse the repository at this point in the history
* Validate sign up form elements on page reload

* Refactor validate condition to reduce complexity
  • Loading branch information
cypherean authored and lagunasmel committed Mar 2, 2021
1 parent 6d87bf6 commit f8580dd
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions app/assets/javascripts/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,17 @@ $(document).ready(function() {
if (signUpForms[1]) {
signUpForms[1].classList.add("signup-register-form");
var signUpRegisterForm = new SignUpFormValidator(".signup-register-form");
signUpRegisterForm.validateForm()

if (signUpErrorMessages.innerHTML.includes("Email")) {
signUpRegisterForm.updateUI(signUpRegisterForm.emailElement, false, "Email already exists");
if (signUpErrorMessages.innerHTML.includes("error")) {
signUpRegisterForm.updateUI(signUpRegisterForm.emailElement, true);
signUpRegisterForm.updateUI(signUpRegisterForm.usernameElement, true);
if (signUpErrorMessages.innerHTML.includes("Email")) {
signUpRegisterForm.updateUI(signUpRegisterForm.emailElement, false, "Email already exists");
}
if (signUpErrorMessages.innerHTML.includes("Username")) {
signUpRegisterForm.updateUI(signUpRegisterForm.usernameElement, false, "Username already exists");
}
}
signUpRegisterForm.isFormValid()
}

// The same goes for login forms
Expand Down

0 comments on commit f8580dd

Please sign in to comment.