backbone.validation
backbone.validation copied to clipboard
Send model for valid and invalid callbacks
When binding collections to Backbone.Validation may be difficult to identify which of the models is invalid. I end up doing something like this:
Backbone.Validation.bind(this, {
valid: this._onValid.bind(this),
invalid: this._onInvalid.bind(this),
collection: this.collection
});
_onInvalid: function(view, attr, error){ <-- add model here
var $form = this._getCapacitiesForm();
$form
.find('tr[data-id="' + this.checkedModel.get('id') + '"]')
.find('[data-validation~="' + attr + '"]')
.addClass('has-error')
.find('.help-block')
.removeClass('hidden')
.text(error);
},
this.collection.each(function(model){
this.checkedModel = model; <-- this
if (model.isValid(true)) {
return;
}
}, this);
It would be nice to have the model available as argument for valid
and invalid
callbacks.
Thanks
This is fixed in a fork i'm maintaining (tried contact this repository admins without luck): https://github.com/blikblum/backbone.validation
The updated package can be found at https://www.npmjs.com/package/backbone.validation
To use with node: npm install backbone.validation