Saturday, 24 August 2013

Capturing form submit events using enter in backbone

Capturing form submit events using enter in backbone

My backbone.js form has a single textfield (no submit button). I need to
capture submit event (using enter key) in the view. Below is the sample
code. Somehow the submit method is not called on pressing enter. Instead
the form goes for a reload.
<script>
var FormView = Backbone.View.extend({
el : '#form',
events: {
"submit":"submit",
},
initialize: function() {
console.log("initialize");
},
submit : function(e) {
e.preventDefault();
console.log("submit");
}
});
new FormView();
</script>
<form id="form">
<input type="text"/>
</form>

No comments:

Post a Comment