Bootstrap modal window does not close - javascript

I am using Bootstrap modal in a react application . I have a requirement that the modal window should not close when clicking on modal backdrop . For this I am using
$(".modal").modal("backdrop":"static");
which works perfectly fine . But in the next scenario , I want the same modal to close on clicking on backdrop using the following code.
$(".modal").modal("backdrop":true);
But this is not working .
I tried this too
$('#modal').modal('hide');
Please provide a feasible solution for the same.

To close bootstrap modal you can pass 'hide' as option to modal method as follow
$('#modal').modal('hide');
Bootstrap also provide events that you can hook into modal functionality, like if you want to fire a event when the modal has finished being hidden from the user you can use hidden.bs.modal event you can read more about modal methods and events here in Documentation

When you pass an object to the modal function, you can pass these properties
For closing the modal, you should use $(".modal").modal("hide") link

Related

How to open/close modal in tailwind-elements with javascript function?

I use modal from https://tailwind-elements.com/docs/standard/components/modal/
in laravel/alpinejs app and looking at these examples I see that modal is opened/closed with
data-bs-target link .
How can I open/close this modal with javascript?
I need to assign on Save button javascript function and run axios request.
On succes I need to hide this modal
Thanks!

Bootstrap Modal closing when any modal inside is closed

I am using basic bootstrap modal inside which there is a summernote text area. Problem is when I click on the insert picture button in summernote, it again opens a modal to choose the picture, but if I click on the modal close button of the summernote picture modal without choosing the picture, it closes the main modal too.
I don't want to close the main modal when modal close of the picture modal is clicked. Any help would be appreciated....
Check that these modals do not share the same id attribute
Also check that they do not share the same name attribute
you can give them separate names manually (like numbers: modal1)
you can also name them automatically with your server-side language when creating them, or with JavaScript upon load, but remember to reference these names correctly in the references, buttons & functions that close them.
#argon 's solution didn't work for me.
But I found this solution (provided here):
('#HtmlContent').summernote( {
dialogsInBody: true,
});

Bootstrap Modal Close

I have a 2 modals in the root of my markup and although the docs say not to use more than one at a time I have a scenario where from a users perspective I think it would make the most sense to have 2 modals. Problem is that once the second modal opens, it will dismiss the first as well as the second. Is there any way to target a specific modal or id with data-dismiss="modal" as I am assuming this is where the logic for dismissing modals is?
$('#myModal').modal('hide');
Is the correct syntax to close/hide the modal with id myModal (you can test this on the Bootstrap documentation page).
I'd use JQuery//Bootstrap to close them like:
$('#modal1').modal('hide');
EDIT:CMedina was faster ;)

Bootstrap multiple modal dismiss all with the last modal

How can i create multiple overlapping modal popups, and dismiss all the modals with the close button (data-dismiss) on the last modal.
Thanks in advance.
You should be able to create multiple modals, that will naturally overlap each other based on the order they were clicked in. Then, on whatever modal you want to be able to close all modals, you can use this, adjusting it to your liking:
$('.modal').modal('hide');
Stacking modals isn't supported out-of-the-box in Bootstrap, you'll need to fiddle with the JS (& possibly CSS) yourself:
Overlapping modals not supported
Be sure not to open a modal while another is still visible. Showing more than one modal at a time requires custom code.

jQuery magnific-popup submit button

Is it possible to make an extra button on the jquery magnific-popup component, with the functionality to close the dialog?
I'm using the component to add a description to a photo, therefor I'll need a submit button that will add the description via ajax to the photo (this happens already) but the dialog isn't closing...
After reading the doc closely you can do it like:
$.magnificPopup.close(); // Close popup that is currently opened (shorthand)
$('.element-with-popup').magnificPopup('close'); // Will closethe popup

Categories

Resources