Skip to content

Commit d29ebad

Browse files
committed
fix(pat modal): Wait a tick before destroying the modal so that registered event handlers (like form submit) can kick in before the modal disappears.
1 parent c4ea964 commit d29ebad

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/pat/modal/modal.js

+8-13
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ export default Base.extend({
193193
utils.redraw(this.$el.find(".panel-body"));
194194
}
195195
},
196-
destroy() {
197-
// if working without injection, destroy right away.
196+
async destroy() {
197+
await utils.timeout(1); // wait a tick for event handlers (e.g. form submit) have a chance to kick in first.
198198
$(document).off(".pat-modal");
199199
this.$el.remove();
200200
$("body").removeClass("modal-active");
@@ -204,20 +204,15 @@ export default Base.extend({
204204
if (this.$el.find("form").hasClass("pat-inject")) {
205205
// if pat-inject in modal form, listen to patterns-inject-triggered and destroy first
206206
// once that has been triggered
207-
let destroy_handler = () => {
208-
$(document).off(".pat-modal");
209-
this.$el.remove();
210-
$("body").removeClass("modal-active");
211-
$("body").removeClass("modal-panel");
207+
const destroy_handler = () => {
208+
this.destroy();
212209
$("body").off("patterns-inject-triggered", destroy_handler);
213210
};
214-
$("body").on("patterns-inject-triggered", destroy_handler);
211+
$("body").on("patterns-inject-triggered", destroy_handler.bind(this));
215212
} else {
216-
// if working without injection, destroy right away.
217-
$(document).off(".pat-modal");
218-
this.$el.remove();
219-
$("body").removeClass("modal-active");
220-
$("body").removeClass("modal-panel");
213+
// if working without injection, destroy after waiting a tick to let
214+
// eventually registered on-submit handlers kick in first.
215+
this.destroy();
221216
}
222217
},
223218
});

0 commit comments

Comments
 (0)