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
When binding collections to Backbone.Validation may be difficult to identify which of the models is invalid. I end up doing something like this:
It would be nice to have the model available as argument for
validandinvalidcallbacks.Thanks