How to open a new Modal, AND close the existing Modal

Open to all! Ask other shopowners for help.
Post Reply
ArtcoInc
Contributor
Posts: 119
Joined: Fri Oct 25, 2019 4:19 pm
Phoenix Version: v1.0.3.0
Has thanked: 86 times
Been thanked: 17 times

How to open a new Modal, AND close the existing Modal

Post by ArtcoInc »

(Bootstrap 4, PHP 7)

In my store, I have a modal. Within that modal, I have a button that opens a 2nd Modal:

Code: Select all

                <div data-toggle="modal" data-target="#ModalLogin">
                  <?php echo tep_draw_button(IMAGE_BUTTON_CHECKOUT, 'fas fa-angle-right', NULL , 'primary', NULL, 'btn-success'); ?>
                </div>
This works, but the first Modal is still open. How can I open the 2nd Modal AND close the 1st?

TIA

Malcolm


Join The Code Co-op to get access to your library in the Code Co-op Forum
ArtcoInc
Contributor
Posts: 119
Joined: Fri Oct 25, 2019 4:19 pm
Phoenix Version: v1.0.3.0
Has thanked: 86 times
Been thanked: 17 times

Re: How to open a new Modal, AND close the existing Modal

Post by ArtcoInc »

This works:

Code: Select all

                <div class="close" data-dismiss="modal" data-toggle="modal" data-target="#ModalLogin">
BUT, the resulting button is a faded green, not the dark green as normal.

Malcolm
User avatar
burt
Core Team
Posts: 4551
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: How to open a new Modal, AND close the existing Modal

Post by burt »

I think you would need to do some jQuery (as you are on BS4).

In simple terms, when the second one fires, hide the first.

Code: Select all

$(document).ready(function() {
  $('#secondModal').on('show.bs.modal', function () {
    $('#firstModal').modal('hide');
  });
});
Change #secondModal and #firstModal to whatever their ID's are.
In your case, one of them would need to be #ModalLogin.

Note that modals on modals gets messy when it comes to accessibility.
I am not here to build for you.
I am here to build with you. Let's help each other.


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply