Skip to content

Instantly share code, notes, and snippets.

@hwclass
Last active August 29, 2015 14:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hwclass/298aba8455cc57eec460 to your computer and use it in GitHub Desktop.
Save hwclass/298aba8455cc57eec460 to your computer and use it in GitHub Desktop.
Validator.showErrors = function() {
for(var count=0; count < this.errors.length; count++){
console.log(this.errors[count])
}
}
Validator.decorators = {
hasName : {
validate : function(form) {
if (form.name) {
console.log('The form has name.')
} else {
Validator.errors.push('No name!');
}
}
},
hasAge : {
validate : function(form) {
if (form.age) {
console.log('The form has age.')
} else {
Validator.errors.push('No age!')
}
}
},
hasZipCode : {
validate : function(form) {
if (form.zipCode) {
console.log('The form has zip code.')
} else {
Validator.errors.push('No zip code!')
}
}
}
}
Validator.decorators.hasName.validate(form);
Validator.decorators.hasAge.validate(form);
Validator.decorators.zipCode.validate(form);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment