Skip to content

Instantly share code, notes, and snippets.

@snadahalli
Created June 21, 2013 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snadahalli/5831016 to your computer and use it in GitHub Desktop.
Save snadahalli/5831016 to your computer and use it in GitHub Desktop.
Model validation in Backbone.js
var Todo = Backbone.Model.extend({
url: '/todo',
defaults: {
'itemtext' : '',
'priority': ''
},
validate: function (attrs) {
var errors = [];
if (!attrs.itemtext) {
errors.push({name: 'itemtext', message: 'Todo item can not be empty..'});
}
return errors.length > 0 ? errors : false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment