@@ -193,8 +193,8 @@ export default Base.extend({
193
193
utils . redraw ( this . $el . find ( ".panel-body" ) ) ;
194
194
}
195
195
} ,
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 .
198
198
$ ( document ) . off ( ".pat-modal" ) ;
199
199
this . $el . remove ( ) ;
200
200
$ ( "body" ) . removeClass ( "modal-active" ) ;
@@ -204,20 +204,15 @@ export default Base.extend({
204
204
if ( this . $el . find ( "form" ) . hasClass ( "pat-inject" ) ) {
205
205
// if pat-inject in modal form, listen to patterns-inject-triggered and destroy first
206
206
// 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 ( ) ;
212
209
$ ( "body" ) . off ( "patterns-inject-triggered" , destroy_handler ) ;
213
210
} ;
214
- $ ( "body" ) . on ( "patterns-inject-triggered" , destroy_handler ) ;
211
+ $ ( "body" ) . on ( "patterns-inject-triggered" , destroy_handler . bind ( this ) ) ;
215
212
} 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 ( ) ;
221
216
}
222
217
} ,
223
218
} ) ;
0 commit comments