Created
July 10, 2012 16:58
-
-
Save interstateone/3084696 to your computer and use it in GitHub Desktop.
Using backbone-forms with CoffeeScript class syntax
This file contains hidden or 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
define (require) -> | |
# Vendor Libs | |
$ = require 'jquery' | |
_ = require 'underscore' | |
Backbone = require 'backbone' | |
require 'backbone-forms' | |
require 'backbone-forms-bootstrap' | |
class Form extends Backbone.Form | |
initialize: (options) -> | |
_.extend options ?= {}, | |
schema: @schema | |
template: @template | |
fieldsets: @fieldsets | |
super options | |
render: -> | |
options = @options | |
template = @template ? Form.templates[options.template] | |
# Create el from template | |
if _.isFunction template then $form = $ template fieldsets: '<b class="bbf-tmp"></b>' | |
else $form = $ _.template template, fieldsets: '<b class="bbf-tmp"></b>' | |
# Render fieldsets | |
$fieldsetContainer = $ '.bbf-tmp', $form | |
$fieldsetContainer.append @renderFieldset fieldset for fieldset in options.fieldsets | |
$fieldsetContainer.children().unwrap() | |
# Set the template contents as the main element; removes the wrapper element | |
@setElement $form | |
@ |
This file contains hidden or 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
define (require) -> | |
# Vendor Libs | |
$ = require 'jquery' | |
_ = require 'underscore' | |
Backbone = require 'backbone' | |
Marionette = require 'marionette' | |
Form = require 'form' | |
class LoginView extends Form | |
template: require('jade!../templates/login')() | |
schema: | |
email: | |
validate: ['required', 'email'] | |
password: | |
type: 'Password' | |
fieldsets: [ | |
fields: ['email', 'password'] | |
legend: 'Log In' | |
] | |
events: | |
'submit': 'clickedLogin' | |
'click .forgot': 'clickedForgot' | |
clickedLogin: (e) -> | |
e.preventDefault() | |
e.stopPropagation() | |
email = @$('#email').val() | |
password = @$('#password').val() | |
app.vent.trigger 'user:sign-in', email, password | |
clickedForgot: (e) -> | |
e.preventDefault() | |
e.stopPropagation() | |
email = @$('#email').val() | |
app.vent.trigger 'user:forgot', email |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment