Skip to content

Commit

Permalink
Allows array of validators without them being wrapped in objects
Browse files Browse the repository at this point in the history
  • Loading branch information
fridays committed Mar 19, 2016
1 parent 0ab7e30 commit f254d95
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/backbone-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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],
Expand Down

0 comments on commit f254d95

Please sign in to comment.