Skip to content

Commit 5dc7619

Browse files
Update app.js
Added fix for nested modals closing parent modals
1 parent 8b5f2e0 commit 5dc7619

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

js/app.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,3 +401,33 @@ $(document).ready(function() {
401401
// Data Tables
402402
new DataTable('.dataTables');
403403
});
404+
405+
/*
406+
|---------------------------------------------------------------
407+
| Nested Modal Fix for Bootstrap/AdminLTE
408+
| Prevents parent modals from closing when a child modal closes
409+
|---------------------------------------------------------------
410+
*/
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+
});
426+
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+
});

0 commit comments

Comments
 (0)