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

Updated Backbone.Validations to work with Backbone 0.9.10 #34

Merged
merged 1 commit into from
Jan 24, 2013

Conversation

spmason
Copy link
Contributor

@spmason spmason commented Jan 24, 2013

Backbone 0.9.10 has some fairly big changes to validation, though the changes to Backbone.Validations are confined to the newPerformValidation function

I've just made it re-use the default Backbone._validate function instead of re-implementing it, to save some hassle. Some extra work is required to raise invalid:prop events, you wouldn't have to override _validate at all if it didn't have to raise these..

For reference, the new behaviour is as follows:

  • invalid events are now raised for validation errors as error is now reserved for xhr errors (this is badly documented but the correct behaviour: Failed validation does not trigger error callback jashkenas/backbone#2153)
  • To get validation to fire on set, call with {validate: true} (I had to update the unit tests)
  • The error callback is not called on validation errors, you can inspect the model.validationError property instead, immediately after calling save

… style:

- Re-use & extend the default Backbone.validate function instead of re-implementing
- Raise 'invalid' events on error as 'error' is reserved for xhr errors
- 'error' callback is not called on validation errors
- To get validation to fire on 'set', call with {validate: true} in unit tests
@nealstewart
Copy link
Owner

Looks great!

Thanks for updating the tests. You rule.

nealstewart pushed a commit that referenced this pull request Jan 24, 2013
Updated Backbone.Validations to work with Backbone 0.9.10
@nealstewart nealstewart merged commit 7062c82 into nealstewart:master Jan 24, 2013
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

Successfully merging this pull request may close these issues.

2 participants