Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,76 @@
}
}
};

/*
* @public
* Accepts a single field name and evaluates against rules for that field
* @param key A string identifying the field as passed to the constructurthe location of the image, relative to the url argument
* @return returns an array of error objects unless validation passes in which case returns true
*/
FormValidator.prototype.validateOne = function(key) {
var field = this.fields[key] || {},
element = this.form[field.name];
/* reset the errors array */
this.errors = [];

if (element && element !== undefined) {
field.id = attributeValue(element, 'id');
field.element = element;
field.type = (element.length > 0) ? element[0].type : element.type;
field.value = attributeValue(element, 'value');
field.checked = attributeValue(element, 'checked');

/*
* Run through the rules for each field.
* If the field has a depends conditional, only validate the field
* if it passes the custom function
*/

if (field.depends && typeof field.depends === "function") {
if (field.depends.call(this, field)) {
this._validateField(field);

if (this.errors.length > 0){
// console.log('eerrs', this.errors)

return this.errors;
} else {

// console.log('no ers')

return true;
}

}
} else if (field.depends && typeof field.depends === "string" && this.conditionals[field.depends]) {
if (this.conditionals[field.depends].call(this,field)) {
this._validateField(field);

if (this.errors.length > 0){

return this.errors;
} else {

return true;
}

}
} else {

this._validateField(field);

if (this.errors.length > 0){

return this.errors;
} else {

return true;
}
}
}
return true;
}

/**
* private function _getValidDate: helper function to convert a string date to a Date object
Expand Down