Every time I create a view and open the dialog, I get n
sets of events where n
is the number of times the dialog has been opened. In the sample below, each time I click fooButton
I will get n
button click events. I know I'm supposed to unbind events but this.undelegateEvents()
isn't working.
From what I understand about the way SimpleDialog (and other dialog widgets work), the contents of the div are copied into another element when the dialog is created, which suggest that I should be able to capture the created element (say $dialog = this.$el.modal();
) and then call undelegateEvents on that. This approach also isn't working.
Any ideas?
MyDialogView = Backbone.View.extend({
initialize: function(options){
this.render();
},
render: function() {
this.$el.empty().append("<button id='fooButton'>Foo</button>");
this.$el.modal({ "static": true });
},
events: {
"click #fooButton": "fooPressed"
},
fooPressed: function() {
alert("clicked");
$.modal.close();
}
});
$(function(){
$("#openDialog").click(function() {
new MyDialogView({el: $("#dialog") });
});
});
​Thanks for your help!
Solved by switching to JQuery UI Dialog. See my answer below.