Created
July 21, 2008 20:32
-
-
Save cannikin/131 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
// validate all the fields in the form | |
validateForm:function() { | |
this.resetForm(); | |
this.fields.each(function(field) { | |
this.validateField(field); | |
}.bind(this)); | |
return this.hasErrors() ? false : true; | |
}, | |
// validate a specific field | |
validateField:function(e) { | |
// is this being called as the result of an event being fired, or did we call it directly? | |
var obj = Event.element(e) ? Event.element(e) : $(e); | |
var fields = this.fields.select(function(field) { | |
return obj == field.obj ? true : false; | |
}); | |
if(fields) { | |
this.resetField(fields[0]); | |
// for each field that matched, first check to see if it already has an error and if not, then validate | |
fields.each(function(field) { | |
if(!this.fieldHasErrors(field)) { | |
if(field.method($F(field.obj))) { | |
this.setFieldAsValid(field); | |
} else { | |
this.setFieldAsError(field); | |
} | |
} | |
}.bind(this)); | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment