Skip to content

Send model for valid and invalid callbacks #346

@alexandrubau

Description

@alexandrubau

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions