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
2 changes: 1 addition & 1 deletion dist/backbone-validation-amd-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 33 additions & 7 deletions dist/backbone-validation-amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,49 @@

// Check whether or not a value, or a hash of values
// passes validation without updating the model
preValidate: function(attr, value) {
preValidate: function(attr, enteredValue) {
var self = this,
result = {},
error;
result = {},
error;

if(_.isObject(attr)){

_.each(attr, function(value, key) {
error = self.preValidate(key, value);
if(error){
result[key] = error;

if (typeof value === 'object' && !(
value instanceof Array ||
value instanceof Date ||
value instanceof RegExp ||
value instanceof Backbone.Model ||
value instanceof Backbone.Collection)
) {
// We now have complex object, so we need to flatten
var flattened = flatten(value);

_.each(flattened, function (val, ki) {

error = self.preValidate(key + '.' + ki, val);

if(error){
result[key + '.' + ki] = error;
}
});

}
else {
error = self.preValidate(key, value);
if(error) {
result[key] = error;
}
}

});

return _.isEmpty(result) ? undefined : result;
}
else {
return validateAttr(this, attr, value, _.extend({}, this.attributes));

return validateAttr(this, attr, enteredValue, _.extend({}, this.attributes));
}
},

Expand Down
Loading