Merge pull request #12 from juggy/validation-fix

Async validations should not trump previous validations Part#2
This commit is contained in:
1602 2011-11-26 00:10:14 -08:00
commit 66e311f8a0
1 changed files with 7 additions and 3 deletions

View File

@ -116,7 +116,6 @@ Validatable.prototype.isValid = function (callback) {
var inst = this;
this.constructor._validations.forEach(function (v) {
if (v[2] && v[2].async) {
valid = false;
async = true;
wait += 1;
validationFailed(inst, v, done);
@ -133,6 +132,7 @@ Validatable.prototype.isValid = function (callback) {
asyncFail = asyncFail || fail;
if (--wait === 0 && callback) {
validationsDone.call(inst, function () {
if( valid && !asyncFail ) cleanErrors(inst);
callback(valid && !asyncFail);
});
}
@ -140,8 +140,12 @@ Validatable.prototype.isValid = function (callback) {
});
if (valid) cleanErrors(this);
if (!async && callback) callback(valid);
if (!async) {
if (valid) cleanErrors(this);
if (callback) callback(valid);
}
return valid;
};