-
-
Save mervick/97ee860f4dad8b022893af4cdb4bd382 to your computer and use it in GitHub Desktop.
Backbone.js form submission
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([ | |
'backbone', | |
'underscore', | |
'project/views/form' | |
], function(Backbone, _, ProjectFormView) { | |
var View = Backbone.View.extend({ | |
events: { | |
'submit form': 'submit' | |
}, | |
initialize: function() { | |
this.model.bind('change:project', this.render, this); | |
}, | |
render: function() { | |
var project = this.model.get('project'); | |
var form = new ProjectFormView({ el: this.$('.container'), model: project }); | |
form.render(); | |
return this; | |
}, | |
submit: function(e) { | |
e.preventDefault(); | |
this.collection.create({ | |
name: this.$('input[name=name]').val(), | |
key: this.$('input[name=key]').val() | |
}); | |
Backbone.history.navigate('#projects', true); | |
} | |
}); | |
return View; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment