Created
February 24, 2012 17:40
-
-
Save toddself/1902302 to your computer and use it in GitHub Desktop.
Backbone.Validator usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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