Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send model for valid and invalid callbacks #346

Open
alexandrubau opened this issue May 2, 2017 · 1 comment
Open

Send model for valid and invalid callbacks #346

alexandrubau opened this issue May 2, 2017 · 1 comment

Comments

@alexandrubau
Copy link

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

@blikblum
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants