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 f254d95 commit fa18794
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions dist/backbone-validation-amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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],
Expand Down Expand Up @@ -715,4 +716,4 @@
return Validation;
}(_));
return Backbone.Validation;
}));
}));

0 comments on commit fa18794

Please sign in to comment.