Skip to content

Instantly share code, notes, and snippets.

@toddself
Created February 24, 2012 17:40
Show Gist options
  • Save toddself/1902302 to your computer and use it in GitHub Desktop.
Save toddself/1902302 to your computer and use it in GitHub Desktop.
Backbone.Validator usage
var TestModel = Backbone.Model.extend({
use_defaults: true,
defaults: {
title: "BAD TITLE"
},
validators: {
title: {
is_type: 'string',
max_length: 40
}
}
}
});
var test_model = new TestModel();
test_model.set({title: "I am a title!"});
test_model.get('title');
"I am a title!"
test_model.set({title: false});
test_model.get('title');
"BAD TITLE"
t.set({title: 'this title is way too long to be set and it should not get set because it is way too long and like if it gets set it will suck because this is way too long'});
t.get('title');
"BAD TITLE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment