From 4be4b1a31b105721166bf4890e1c5e6f48e8f496 Mon Sep 17 00:00:00 2001 From: OHTSUKA Ko-hei Date: Tue, 4 Mar 2014 17:07:25 +0900 Subject: [PATCH] preValidate method cannnot handle conditional validation. so make it possible. --- src/backbone-validation.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/backbone-validation.js b/src/backbone-validation.js index 4e1da56a..5dd3dd5b 100644 --- a/src/backbone-validation.js +++ b/src/backbone-validation.js @@ -177,14 +177,15 @@ Backbone.Validation = (function(_){ // Check whether or not a value, or a hash of values // passes validation without updating the model - preValidate: function(attr, value) { + preValidate: function(attr, value, attrs) { var self = this, result = {}, error; + if (attrs === void 0) attrs = {}; if(_.isObject(attr)){ _.each(attr, function(value, key) { - error = self.preValidate(key, value); + error = self.preValidate(key, value, attr); if(error){ result[key] = error; } @@ -193,7 +194,8 @@ Backbone.Validation = (function(_){ return _.isEmpty(result) ? undefined : result; } else { - return validateAttr(this, attr, value, _.extend({}, this.attributes)); + var checkAttr = _.extend({}, this.attributes); + return validateAttr(this, attr, value, _.extend(checkAttr, attrs)); } },