From 001a9626061e37da2670e2ac6ab5f53268d46174 Mon Sep 17 00:00:00 2001 From: Julien Guimont Date: Fri, 25 Nov 2011 10:43:50 -0500 Subject: [PATCH] Some errors in the previous PR --- lib/validatable.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/validatable.js b/lib/validatable.js index 3f45db48..559b377e 100644 --- a/lib/validatable.js +++ b/lib/validatable.js @@ -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; };