Skip to content

Instantly share code, notes, and snippets.

@p0rsche
Forked from thedersen/Backbone.Validation
Created April 2, 2014 12:05
Show Gist options
  • Save p0rsche/9932798 to your computer and use it in GitHub Desktop.
Save p0rsche/9932798 to your computer and use it in GitHub Desktop.
var Model = Backbone.Model.extend({
validation: {
dependsOn: function(value, attributeName, computedState) {
// computedState is the model's state after the current operation completes.
// You need to get the value of the other attribute from this, and not from the
// model it self because if both attributes are being set at the same time,
// model's value is not yet updated.
if(computedState.someAttribute === 'someValue') {
// If some condition is true, execute the min validator, else don't do anything.
return Backbone.Validation.validators.min(value, attributeName, 5 /*the min value*/, this);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment