Skip to content
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
11 changes: 6 additions & 5 deletions dist/backbone-validation-amd.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Backbone.Validation v0.9.0
//
// Copyright (c) 2011-2013 Thomas Pedersen
// Copyright (c) 2011-2018 Thomas Pedersen
// Distributed under MIT License
//
// Documentation and full license available at:
Expand Down Expand Up @@ -215,15 +215,16 @@
// entire model is valid. Passing true will force a validation
// of the model.
isValid: function(option) {
var flattened = flatten(this.attributes);
var _this = this,
flattened = flatten(this.attributes);

if(_.isString(option)){
return !validateAttr(this, option, flattened[option], _.extend({}, this.attributes));
}
if(_.isArray(option)){
return _.reduce(option, function(memo, attr) {
return memo && !validateAttr(this, attr, flattened[attr], _.extend({}, this.attributes));
}, true, this);
return memo && !validateAttr(_this, attr, flattened[attr], _.extend({}, _this.attributes));
}, true);
}
if(option === true) {
this.validate();
Expand Down Expand Up @@ -611,7 +612,7 @@
// Validates that the value has to be equal to one of the elements in
// the specified array. Case sensitive matching
oneOf: function(value, attr, values, model) {
if(!_.include(values, value)){
if(!_.includes(values, value)){
return this.format(defaultMessages.oneOf, this.formatLabel(attr, model), values.join(', '));
}
},
Expand Down
11 changes: 6 additions & 5 deletions dist/backbone-validation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Backbone.Validation v0.9.0
//
// Copyright (c) 2011-2013 Thomas Pedersen
// Copyright (c) 2011-2018 Thomas Pedersen
// Distributed under MIT License
//
// Documentation and full license available at:
Expand Down Expand Up @@ -208,15 +208,16 @@ Backbone.Validation = (function(_){
// entire model is valid. Passing true will force a validation
// of the model.
isValid: function(option) {
var flattened = flatten(this.attributes);
var _this = this,
flattened = flatten(this.attributes);

if(_.isString(option)){
return !validateAttr(this, option, flattened[option], _.extend({}, this.attributes));
}
if(_.isArray(option)){
return _.reduce(option, function(memo, attr) {
return memo && !validateAttr(this, attr, flattened[attr], _.extend({}, this.attributes));
}, true, this);
return memo && !validateAttr(_this, attr, flattened[attr], _.extend({}, _this.attributes));
}, true);
}
if(option === true) {
this.validate();
Expand Down Expand Up @@ -604,7 +605,7 @@ Backbone.Validation = (function(_){
// Validates that the value has to be equal to one of the elements in
// the specified array. Case sensitive matching
oneOf: function(value, attr, values, model) {
if(!_.include(values, value)){
if(!_.includes(values, value)){
return this.format(defaultMessages.oneOf, this.formatLabel(attr, model), values.join(', '));
}
},
Expand Down
9 changes: 5 additions & 4 deletions src/backbone-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,16 @@ Backbone.Validation = (function(_){
// entire model is valid. Passing true will force a validation
// of the model.
isValid: function(option) {
var flattened = flatten(this.attributes);
var _this = this,
flattened = flatten(this.attributes);

if(_.isString(option)){
return !validateAttr(this, option, flattened[option], _.extend({}, this.attributes));
}
if(_.isArray(option)){
return _.reduce(option, function(memo, attr) {
return memo && !validateAttr(this, attr, flattened[attr], _.extend({}, this.attributes));
}, true, this);
return memo && !validateAttr(_this, attr, flattened[attr], _.extend({}, _this.attributes));
}, true);
}
if(option === true) {
this.validate();
Expand Down Expand Up @@ -597,7 +598,7 @@ Backbone.Validation = (function(_){
// Validates that the value has to be equal to one of the elements in
// the specified array. Case sensitive matching
oneOf: function(value, attr, values, model) {
if(!_.include(values, value)){
if(!_.includes(values, value)){
return this.format(defaultMessages.oneOf, this.formatLabel(attr, model), values.join(', '));
}
},
Expand Down