2014
07.13

A very short warning, for those working with backbone views using event delegation. You may already know this, but another friendly notice can’t be bad. Be sure to avoid using focus, blur, change, submit and reset as your backbone view events. Whilst these may work in modern browsers, it will not work in older Internet Explorer.
For example the following will not work in IE 8:
[code lang=”javascript”]
var FormView = Backbone.View.extend({
events: {
‘submit’: ‘handleSubmit’
},
handleSubmit: function(e){
console.log(“Form was submitted”);
this.model.save();
return false;
}
});
[/code]

The main backbone documentation does not seem to mention this rather important fact, although the annotated source does.

How to solve this for IE 8?

In short, I’m not sure. You could try listening for a click on the submit button instead, but that won’t work when the form is submitted by pressing enter on the keyboard. So what I have found works is after your view is rendered, use jQuery to listen to the submit event (this.$el.on(‘submit’ this.handleSubmit). In fact, in most cases I’m still using jQuery validate after the form is rendered. This has a submitHandler callback so you can use that instead.

I’ve seen plenty of examples of people using submit  in their views, including myself. Unfortunately I still need to support IE 8 in my work. I envy those of you who don’t.

No Comment.

Add Your Comment