@@ -404,30 +404,54 @@ $(document).ready(function() {
404404
405405/*
406406 |---------------------------------------------------------------
407- | Nested Modal Fix for Bootstrap/AdminLTE
408- | Prevents parent modals from closing when a child modal closes
407+ | Nested Modal Fix for ITFlow AJAX Modals
408+ | Each modal gets a unique container, parent modals remain open
409409 |---------------------------------------------------------------
410410*/
411- $ ( document ) . on ( 'show.bs.modal' , '.modal' , function ( ) {
412- // How many modals are currently visible?
413- const visibleModals = $ ( '.modal:visible' ) . length ;
414-
415- // Increase z-index for each new modal
416- const zIndex = 1040 + ( 10 * visibleModals ) ;
417- $ ( this ) . css ( 'z-index' , zIndex ) ;
418-
419- // Delay required because Bootstrap inserts backdrop asynchronously
420- setTimeout ( ( ) => {
421- $ ( '.modal-backdrop' ) . not ( '.modal-stack' )
422- . css ( 'z-index' , zIndex - 1 )
423- . addClass ( 'modal-stack' ) ; // mark backdrops so they aren't reset
424- } , 0 ) ;
425- } ) ;
426411
427- // Restore modal-open class when closing a child modal
428- $ ( document ) . on ( 'hidden.bs.modal' , '.modal' , function ( ) {
429- if ( $ ( '.modal:visible' ) . length > 0 ) {
430- // Ensure background scroll remains locked
431- $ ( 'body' ) . addClass ( 'modal-open' ) ;
432- }
433- } ) ;
412+ ( function ( ) {
413+ if ( ! window . createAjaxModal ) return ;
414+
415+ // Keep original function just in case
416+ const originalCreateAjaxModal = window . createAjaxModal ;
417+
418+ window . createAjaxModal = function ( contentHtml ) {
419+ // Generate a unique ID for this modal
420+ const modalId = 'ajaxModal_' + Date . now ( ) ;
421+
422+ // Create a new modal container
423+ const $modal = $ ( '<div class="modal fade" tabindex="-1" aria-hidden="true">' )
424+ . attr ( 'id' , modalId )
425+ . html ( contentHtml )
426+ . appendTo ( 'body' ) ;
427+
428+ // Initialize Bootstrap modal
429+ $modal . modal ( 'show' ) ;
430+
431+ // Ensure only this modal is removed when hidden
432+ $modal . on ( 'hidden.bs.modal' , function ( ) {
433+ $ ( this ) . remove ( ) ;
434+ } ) ;
435+
436+ return $modal ;
437+ } ;
438+
439+ // Optional: Keep proper z-index stacking for multiple nested modals
440+ $ ( document ) . on ( 'show.bs.modal' , '.modal' , function ( ) {
441+ const zIndex = 1040 + ( 10 * $ ( '.modal:visible' ) . length ) ;
442+ $ ( this ) . css ( 'z-index' , zIndex ) ;
443+ setTimeout ( ( ) => {
444+ $ ( '.modal-backdrop' ) . not ( '.modal-stack' )
445+ . css ( 'z-index' , zIndex - 1 )
446+ . addClass ( 'modal-stack' ) ;
447+ } , 0 ) ;
448+ } ) ;
449+
450+ $ ( document ) . on ( 'hidden.bs.modal' , '.modal' , function ( ) {
451+ if ( $ ( '.modal:visible' ) . length > 0 ) {
452+ $ ( 'body' ) . addClass ( 'modal-open' ) ;
453+ }
454+ } ) ;
455+
456+ } ) ( ) ;
457+
0 commit comments