thedersen/backbone.validation — Issue #25: custom invalid function not getting parameters
Author: toddself
Created: 2012-02-22 19:28:52+00:00
State: open

_.extend(Backbone.Model.prototype, Backbone.Validation.mixin);

var test = Backbone.Model.extend({
validation: {
value: {
pattern: 'url'
},
},
initialize: function(){
this.bind('validated: invalid', this.invalid);
},
invalid: function(view, attr, error, selector){
console.log(view, attr, error, selector);
}
});

var t = new Test({value: 'hotdogs'});

When I run this, this is the result from the console:
`>child [] undefined undefined`

Where child is the model that was being validated, but all the other attributes are empty so I'm unaware as to what failed validation.

I'm trying to make it so if there's an invalid setting and there's a default set for that setting, it'll use the default to override the invalid value trying to be set.

Additionally, I *must* bind to validate:invalid in the model's `initialization` function, if I don't it will (nor the method I'm overwriting) get called at all.

Non-view model level validation is super important to us.