From f254d95c2b0c719d6aaabc21412da67312b3324d Mon Sep 17 00:00:00 2001 From: fridays Date: Sat, 19 Mar 2016 07:25:37 +0100 Subject: [PATCH] Allows array of validators without them being wrapped in objects --- src/backbone-validation.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/backbone-validation.js b/src/backbone-validation.js index e4aa8de2..869c12e4 100644 --- a/src/backbone-validation.js +++ b/src/backbone-validation.js @@ -127,13 +127,6 @@ Backbone.Validation = (function(_){ var getValidators = function(model, attr) { var attrValidationSet = model.validation ? _.result(model, 'validation')[attr] || {} : {}; - // If the validator is a function or a string, wrap it in a function validator - if (_.isFunction(attrValidationSet) || _.isString(attrValidationSet)) { - attrValidationSet = { - fn: attrValidationSet - }; - } - // Stick the validator object into an array if(!_.isArray(attrValidationSet)) { attrValidationSet = [attrValidationSet]; @@ -143,6 +136,14 @@ Backbone.Validation = (function(_){ // with a validation method to call, the value to validate against // and the specified error message, if any return _.reduce(attrValidationSet, function(memo, attrValidation) { + + // If the validator is a function or a string, wrap it in a function validator + if (_.isFunction(attrValidation) || _.isString(attrValidation)) { + attrValidation = { + fn: attrValidation + }; + } + _.each(_.without(_.keys(attrValidation), 'msg'), function(validator) { memo.push({ fn: defaultValidators[validator],