From 358f7b788ca118e80a9fd66d28d8fd74fdf54630 Mon Sep 17 00:00:00 2001 From: Anatoliy Chakkaev Date: Fri, 1 Mar 2013 21:13:04 +0700 Subject: [PATCH] FIxes in async validations (in sync case), closes 214 --- lib/validatable.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/validatable.js b/lib/validatable.js index 06f1ac71..50a8e939 100644 --- a/lib/validatable.js +++ b/lib/validatable.js @@ -351,12 +351,16 @@ Validatable.prototype.isValid = function (callback) { }); this.trigger('validation', function (validationsDone) { - var inst = this; + var inst = this, + asyncFail = false; + this.constructor._validations.forEach(function (v) { if (v[2] && v[2].async) { async = true; wait += 1; - validationFailed(inst, v, done); + process.nextTick(function () { + validationFailed(inst, v, done); + }); } else { if (validationFailed(inst, v)) { valid = false; @@ -369,7 +373,6 @@ Validatable.prototype.isValid = function (callback) { validationsDone(); } - var asyncFail = false; function done(fail) { asyncFail = asyncFail || fail; if (--wait === 0 && callback) {