Skip to content

Instantly share code, notes, and snippets.

@ivasilov
Created February 7, 2012 23:07
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 ivasilov/1762823 to your computer and use it in GitHub Desktop.
Save ivasilov/1762823 to your computer and use it in GitHub Desktop.
Model validation
# My model
class exports.Item extends Backbone.Model
validation:
item:
required: true
quantity:
required: true
pattern: 'number'
price:
required: true
pattern: 'number'
#Part of the view
class exports.ItemView extends Backbone.View
tagName: 'tr'
events:
...
initialize: ->
@model.bind('change' , @render, @)
@model.bind('destroy', @remove, @)
Backbone.Validation.bind @,
valid: (view,attr) ->
view.$('#' + attr).removeClass('error')
invalid: (view,attr,error) ->
view.$('#' + attr).addClass('error')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment