Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple live error messages now appear for signup page #13

Merged
merged 1 commit into from
Jan 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions static/js/validate.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
$(document).ready(function(){

// The blur event is for when a selector has lost focus
$("#username").blur(function(){
var $form = $('form.sign-in');
$('.error').html("");

var $username = $form.find('#username');
var isValidUsername = isPresent($username) && isValidName($username);
Expand All @@ -16,7 +16,6 @@ $(document).ready(function(){
$("#nickname").blur(function(){

var $form = $('form.sign-in');
$('.error').html("");

var $nickname = $form.find('#nickname');
var isValidNickname = isPresent($nickname) && isValidName($nickname);
Expand All @@ -32,7 +31,6 @@ $(document).ready(function(){
$("#password").blur(function(){

var $form = $('form.sign-in');
$('.error').html("");

var $password = $form.find('#password');
var validPassword = isValidPassword($password);
Expand All @@ -41,12 +39,13 @@ $(document).ready(function(){
return true;
} else {
return false;
}

});

$('#email').blur(function(){

var $form = $('form.sign-in');
$('.error').html("");

var $email = $form.find('#email');
var validEmail = isPresent($email) && isValidEmail($email);
Expand All @@ -63,22 +62,20 @@ $(document).ready(function(){
return validateSignupForm();
});

return validateForm();


$('.post_submit').click(function(evt){
return validatePost();
});



function isPresent($input) {
if ($input.val().length < 4) {
$input.parent()
.find('.error')
.text('At least four characters are required in this field.')
.text('At least four characters are required in this field')
return false;
} else {
$input.parent()
.find('.error')
.text('')
return true;
}
}
Expand All @@ -88,9 +85,12 @@ $(document).ready(function(){
if (!emailReg.test($input.val())) {
$input.parent()
.find('.error')
.text('This is not a valid email address.')
.text('This is not a valid email address format')
return false;
} else {
$input.parent()
.find('.error')
.text('')
return true;
}
}
Expand All @@ -103,29 +103,29 @@ $(document).ready(function(){
.text('Usernames and nicknames can only contain letters and numbers.')
return false;
} else {
$input.parent()
.find('.error')
.text('')
return true;
}
}


function validateName($name) {

var validName = isPresent($name) && isValidName($name);
return validName;

}

function isValidPassword($input){
if ($input.val().length < 8) {
if ($input.val().length < 8) {
$input.parent()
.find('.error')
.text('At least eight characters are required in this field')
.text('At least eight characters are required in this field.')
return false;
} else {
$input.parent()
.find('.error')
.text('')
return true;
}
}



function validateSignupForm() {
var $form = $('form.sign-in');
$('.error').html("");
Expand Down Expand Up @@ -156,7 +156,7 @@ $(document).ready(function(){

if (validQuestion) {
return true;
} else {
}else {
return false;
}
}
Expand Down