From f254d95c2b0c719d6aaabc21412da67312b3324d Mon Sep 17 00:00:00 2001 From: fridays Date: Sat, 19 Mar 2016 07:25:37 +0100 Subject: [PATCH 1/3] 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], From fa187949bbb836770c975d3cdc8cc76b1b385835 Mon Sep 17 00:00:00 2001 From: fridays Date: Sat, 19 Mar 2016 07:33:33 +0100 Subject: [PATCH 2/3] Allows array of validators without them being wrapped in objects Fix for #331 --- dist/backbone-validation-amd.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/dist/backbone-validation-amd.js b/dist/backbone-validation-amd.js index 6f90e318..43db9b36 100644 --- a/dist/backbone-validation-amd.js +++ b/dist/backbone-validation-amd.js @@ -141,13 +141,6 @@ 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]; @@ -157,6 +150,14 @@ // 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], @@ -715,4 +716,4 @@ return Validation; }(_)); return Backbone.Validation; -})); \ No newline at end of file +})); From b7dd6ddfd8c5f4673fa75ae27795f0e18f6f89be Mon Sep 17 00:00:00 2001 From: fridays Date: Sat, 19 Mar 2016 07:39:13 +0100 Subject: [PATCH 3/3] Allows array of validators without them being wrapped in objects --- dist/backbone-validation.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/dist/backbone-validation.js b/dist/backbone-validation.js index e1d10e10..52bbe5f0 100644 --- a/dist/backbone-validation.js +++ b/dist/backbone-validation.js @@ -134,13 +134,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]; @@ -150,6 +143,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], @@ -706,4 +707,4 @@ Backbone.Validation = (function(_){ }); return Validation; -}(_)); \ No newline at end of file +}(_));