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

FAQ - What gets validated when? #200

Open
cooolbasha opened this issue Jan 21, 2014 · 3 comments
Open

FAQ - What gets validated when? #200

cooolbasha opened this issue Jan 21, 2014 · 3 comments

Comments

@cooolbasha
Copy link

How to validate just the one's that are set. Is there another method other than model.isValid(true) or model.validate() which would not validates the complete model. Here are some config that is there in my code

_.extend Backbone.Model.prototype, Backbone.Validation.mixin
Backbone.Validation.configure
        forceUpdate: true

setting one attribute with {validate:true} is triggering validate on the entire model

Thanks

@arobinson
Copy link

I'm having the same issue. I only want callbacks on the view for the attributes that are passed to validate.

For example:

model.validate({ subject: this.getValue() })

In this code, where "this" is a view widget for the subject attribute, I only expect the Backbone.Validation.callbacks to be called with valid or invalid for just the "subject" attribute. Instead I'm getting called for every attribute on the model.

This is a very bad design, assuming that the model has been changed by the view. In my case, it is important that the model is only updated when the "save" button is clicked. I validate each field on blur of the widget. So I want to show errors based on the form values, not the model attributes.

@hjc
Copy link

hjc commented Feb 5, 2014

Check out prevalidate, let's you pass a hash of values (with model properties as their keys) to a model and it only validates the given keys. It then returns whatever validate would return, so a null/undefined on validation pass and anything else on failure.

@giiska
Copy link

giiska commented Feb 20, 2014

This alternative https://github.com/fantactuka/backbone-validator can do so.

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

4 participants