@@ -43,13 +43,15 @@ export function initGlobalDeleteButton(): void {
4343
4444 fomanticQuery ( modal ) . modal ( {
4545 closable : false ,
46- onApprove : async ( ) => {
46+ onApprove : ( ) => {
4747 // if `data-type="form"` exists, then submit the form by the selector provided by `data-form="..."`
4848 if ( btn . getAttribute ( 'data-type' ) === 'form' ) {
4949 const formSelector = btn . getAttribute ( 'data-form' ) ;
5050 const form = document . querySelector < HTMLFormElement > ( formSelector ) ;
5151 if ( ! form ) throw new Error ( `no form named ${ formSelector } found` ) ;
52+ form . classList . add ( 'is-loading' ) ;
5253 form . submit ( ) ;
54+ return false ; // prevent modal from closing automatically
5355 }
5456
5557 // prepare an AJAX form by data attributes
@@ -62,12 +64,14 @@ export function initGlobalDeleteButton(): void {
6264 postData . append ( 'id' , value ) ;
6365 }
6466 }
65-
66- const response = await POST ( btn . getAttribute ( 'data-url' ) , { data : postData } ) ;
67- if ( response . ok ) {
68- const data = await response . json ( ) ;
69- window . location . href = data . redirect ;
70- }
67+ ( async ( ) => {
68+ const response = await POST ( btn . getAttribute ( 'data-url' ) , { data : postData } ) ;
69+ if ( response . ok ) {
70+ const data = await response . json ( ) ;
71+ window . location . href = data . redirect ;
72+ }
73+ } ) ( ) ;
74+ return false ; // prevent modal from closing automatically
7175 } ,
7276 } ) . modal ( 'show' ) ;
7377 } ) ;
@@ -158,13 +162,7 @@ function onShowModalClick(el: HTMLElement, e: MouseEvent) {
158162 }
159163 }
160164
161- fomanticQuery ( elModal ) . modal ( 'setting' , {
162- onApprove : ( ) => {
163- // "form-fetch-action" can handle network errors gracefully,
164- // so keep the modal dialog to make users can re-submit the form if anything wrong happens.
165- if ( elModal . querySelector ( '.form-fetch-action' ) ) return false ;
166- } ,
167- } ) . modal ( 'show' ) ;
165+ fomanticQuery ( elModal ) . modal ( 'show' ) ;
168166}
169167
170168export function initGlobalButtons ( ) : void {
0 commit comments