Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows array of validators without them being wrapped in objects #332

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}));
}));
17 changes: 9 additions & 8 deletions dist/backbone-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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],
Expand Down Expand Up @@ -706,4 +707,4 @@ Backbone.Validation = (function(_){
});

return Validation;
}(_));
}(_));
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