awkward / backbone.modal

A plugin for Backbone.js that simplifies creating modals for your application.
http://awkward.github.io/backbone.modal/
Other
362 stars 71 forks source link

delegateModalEvents() doesn't undelegate events first #105

Open kevinhb opened 5 years ago

kevinhb commented 5 years ago

The default Backbone delegateEvents() includes a call to undelegateEvents() so that all events on the view will be refreshed when it's called inside render(). However, delegateModalEvents() does NOT include an equivalent call to undelegateModalEvents(). This means that, if you re-render a Modal without first calling undelegateModalEvents(), the default implementation of render() will cause all of your events (including implicit Backbone.Modal events such as submit and cancel!) to be bound AGAIN, which results in all submit/cancel callbacks firing multiple times for a single button click.

I can't imagine a single sane reason why you would want to delegate events in this function without undelegating first (hence the Backbone behavior, duh) and the current behavior requires making an extra function call before every call to render() if you want to avoid bugs that, if this were vanilla Backbone, would seem completely inexplicable. delegateModalEvents() should call undelegateModalEvents() before it does anything else.