Skip to content

Instantly share code, notes, and snippets.

@cannikin
Created July 21, 2008 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cannikin/131 to your computer and use it in GitHub Desktop.
Save cannikin/131 to your computer and use it in GitHub Desktop.
// 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