Skip to content

Instantly share code, notes, and snippets.

@milankinen
Last active December 16, 2015 22:09
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 milankinen/5505391 to your computer and use it in GitHub Desktop.
Save milankinen/5505391 to your computer and use it in GitHub Desktop.
jQuery ->
# Simple person model with two attributes
class Person extends Backbone.Model
validation:
age:
required: true
min: 10
name:
required: true
msg: "All persons have a name..."
class PersonView extends ItemView
el: $("#person-form")
template: Handlebars.compile($("#person-form-template").html())
events:
"click #send-btn" : 'send'
"click #cancel-btn" : 'cancel'
send: ->
@model.validate()
if @model.isValid()
alert "OK!"
# do some save stuff here
cancel: ->
@model.clear()
@render()
view = new PersonView(model: new Person())
view.render()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment