Last active
August 29, 2015 14:05
-
-
Save hwclass/298aba8455cc57eec460 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
Validator.showErrors = function() { | |
for(var count=0; count < this.errors.length; count++){ | |
console.log(this.errors[count]) | |
} | |
} |
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
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!') | |
} | |
} | |
} | |
} |
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
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