documentcloud/backbone — pull request #1972 by tgriesser (2012-12-18 20:41:30+00:00)
Title: Add validate flag to trigger validation of models, default to true on save

From the discussion in #1961 - there are several valid use cases of wanting to create invalid models, including creating a partial model to eventually fetch, and updating attributes individually, as with a form.

Making the `validate` functionality mirror that of an active record object might be the be best approach. With this, models can be modified with invalid attributes, but by default can not be persisted when they're invalid.

This pull request adds the `isValid` method/tests back, as well as adds an extra flag, `{validate:true}` or `{validate:false}`. The flag will default to `true` on save, and `false` everywhere else (`new Model`, `set`, `unset`, `clear`).

`silent:true` is still used strictly for event notification, rather than being mixed in with validation.

The `options` are also passed along from the Model's constructor to `set`, so an error function can be specified to catch instances where `{validate:true}` is set as an option on the constructor.