I am using Cakephp3 and using Bootstrap modals https://getbootstrap.com/docs/4.3/components/modal/ to open my modals once after another something like this way in sequence ..
<a href="/website/orders/view/955792a9a10ae29dc3749308ab244603" data-toggle="ajaxModal" class="text-green priority">ORD0019385</a>
But now what I want to do is to I want to remember the previously opened modal and once I close the last one, It should remember the previous modal and open it..
Here is what I have tried so far ..
$(document).ready(function() {
let modalStack = [];
$(document).on('hidden.bs.modal', '.modal', function () {
if (modalStack.length > 0) {
let lastOpenedModal = modalStack.pop();
$(lastOpenedModal).modal('hide');
$(lastOpenedModal).modal('show');
}
//console.log(modalStack.length);
//console.log('hey');
});
$(document).on('click', '[data-toggle="ajaxModal"]', function (event) {
let currentModal = $(this).closest('.modal');
currentModal.modal('hide');
modalStack.push(currentModal);
console.log(modalStack.length);
});
This code almost working fine as I have tested to open till 3 sequence .. but what's happening is, once I close till 1st modal .. and then reopen my first and then opening my second modal .. then automatically my first modal opens .. This happens when I dont refresh my page and closed all my sequence modals and reopen from the first modal itself ..
Can someone help me what I am doing wrong here in my above code ?
Thanks