Created
February 5, 2015 17:32
-
-
Save andrewhl/39fbf4deebea6cd78abd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var PasswordValidator = function () { | |
var errors = []; | |
return { | |
errors: errors, | |
validateLength: function(password) { | |
if (password.length < 6) { | |
errors.push('The password must be at least 6 characters long.') | |
} | |
}, | |
validate: function(password) { | |
this.validateLength(password); | |
return this.errors; | |
} | |
} | |
}; | |
var UpdatePasswordForm = (function () { | |
var self = this; | |
var formElement = $('#updatePasswordForm'); | |
var passwordField = $(formElement.find('[name="password"]').first()); | |
var validationErrorsBox = $('.password-validation-errors'); | |
var passwordValidationErrorField = validationErrorsBox.find('#passwordValidationError'); | |
var errors = []; | |
var validator = new PasswordValidator(); | |
return { | |
renderPasswordValidationErrors: function () { | |
if (validationErrorsBox.hasClass('hidden')) { | |
validationErrorsBox.fadeIn(300).removeClass('hidden'); | |
} | |
passwordValidationErrorField.text(errors); | |
}, | |
hidePasswordValidationErrors: function () { | |
$('.password-validation-errors').fadeOut(300).addClass('hidden'); | |
}, | |
validatePasswordField: function() { | |
passwordField.on('keydown', function() { | |
var password = this.value; | |
errors = validator.validate(password); | |
if (errors.length >= 1) { | |
self.renderPasswordValidationErrors(); | |
} else { | |
self.hidePasswordValidationErrors(); | |
} | |
//console.log('hola'); | |
//passwordValidationErrorField.text('Validating!'); | |
}); | |
}, | |
hello: function () { | |
console.log(passwordField); | |
} | |
}; | |
})(); | |
window.MatrixApp = {}; | |
window.MatrixApp.UpdatePasswordForm = UpdatePasswordForm; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment