Open a Bootstrap modal from another modal avoiding .modal-backdrop flashing - javascript

I open another modal from a modal by clicking a link inside the first modal (and I also need from te second modal to go back to the first one):
<a onclick="$('.modal-1').modal('hide');$('.modal-2').modal('show');"></a>
And then in the second modal I can go back to the first via another link:
<a onclick="$('.modal-2').modal('hide');$('.modal-1').modal('show');"></a>
But doing it this way makes the '.modal-backdrop' flashing, since in the first case the backdrop of the first modal is fading out whilst the second one is fading in.
Could you help me find a way to prevent the backdrop flashing?
Thank you in advance

Related

Angular open modal doesn't get focused

Within my ts file i open a boostrap modal using the .open command.
Then upon pressing the save button another modal gets open and the previous one gets closed.
Here the problem is that the first modal recieves focus on itself and the elements inside it BUT second modal doesn't get focus!
Here is what is happening:
I click a button and i open a modal A
In modal A i have some html elements including two buttons to save and close the modal
If i click the save button from modal A this modal will get closed and another modal will open
This second opened modal doesn't get focus when pressing TAB
Here is a stackblitz: StackBlitz Demo
How this stackblitz works:
If you click the first button is going to open the modal A
then clicking save on that modal will open another modal B
Inside modal B if you try to tab is going to tab on the elements in the background WHY?
I want to give my second modal focus. I tried with Directives and other things that angular suggest but i haven't been able to get it to work.
I already checked bootstrap documentation, and there is no focus related thing we can use.
You will need to use the setTimeout function with 0ms to force the openSecondModal to run on a different execution cycle. Basically, we need to add a bit of delay for the first modal to close properly before open the second one.
This is a well-known hack. Hopefully, we can write code without using it one day in the future.
modalRef.componentInstance.closeModal.subscribe(() => {
modalRef.close();
setTimeout(() => {
this.openSecondModal();
}, 0);
});

What is making my bootstrap modal disappear on the second time I toggle it?

I have a bootstrap modal with a form inside. The save button makes a post request (via ajax) and then the modal is dismissed using the code below inside the success function.
$("#my-modal-id").modal("hide");
$("body").removeClass("modal-open");
$(".modal-backdrop").remove();
The first time I toggle the modal or if I just cancel the modal, without saving it, I can (re)open it without problem, the issue is after making the ajax request for the first time.
If I click the button that toggles the modal for the second time, it rapidly disappears (the backdrop remains) and to toggle it again I need to refresh the page. When I inspect the page, I see that there is a display attribute set to none on my modal div.
I tried changing from $("#my-modal-id").modal("hide") to $("#my-modal-id").modal("toggle") but it still didn't work.
I am using jQuery v. 2.2.4 (unfortunately).
Does anybody know what could be causing this?

Bootstrap modal shows all images and not limited to the images in any given Tab

My question is about a bootstrap snippet as you can see here:
https://bootsnipp.com/snippets/P2gor
I wanted to use this gallery with tab views as you can see below. But my problem is that when click on first tab (Animal) and open image modal, I see the next button until all images in all tabs are shown. And when I click on second tab (Painting) the modal opens app empty and neither previous nor next button works.
First Tab
Second Tab
I want to be able to use this snippet with Tabs, so I'm here seek advice what can I do to make it work. When I click on first tab and browse the images in the modal, I want the next button to disappear when the last image on the current Tab is shown, not after all other images are shown.
Because there is no argument (id / class) passing to the JavaScript methods, I can't figure out how to make this work without making lots of duplication in the JavaScript file.
I'm sorry if this question is too generic and not enough specific.

Foundation Reveal issue if I have multiple links that opens the same modal popup

I have a page with multiple links that opens a foundation reveal modal. Each link opens the same modal. The problem is that I have some links on the top of the page, and some links on the bottom, so when I click on some link from the top, if I close the modal, the last link get the focus, so the page scrolls down to the last element that opens this unique modal.
Someone knows how can I fix this issue?
See https://github.com/zurb/foundation-sites/issues/10604 . One workaround is to open the modal via js instead of with data-open on each link. ie:
$('.open-my-modal-link').click(function() {
$('#my-modal').foundation('open');
...

Twitter Bootstrap Modal within Modal?

Is it possible to open a modal within another modal with twitter bootstrap?
I created a modal and put a link to a second modal and the definition for a second modal within the first modal body. When I clicked the link the second modal opened on top of the first modal.
I want the second modal to open as if the first modal was the entire window. How can I do that?
Use the jQuery's method html() to replace innerHtml of your first modal by the text.
Here is a JSFiddle Example where you only change the modal window's body.
Here is another JSFiddle Example where you change all modal's content.

Categories

Resources