Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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