bootstrap: Modal doesn't hide when shortly a show
When hiding a modal too soon after showing, it won’t hide.
Reproducable: $("#some-modal").modal('show'); $("#some-modal").modal('hide')
The modal is still shown afterwards. This code seems useless, but in general I use modals for loading pop-ups, to indicate that the user has to wait. Sometimes the loading goes fast causing the hide to be called too shortly after the show in order for the hiding to work.
I fixed it in an ugly way doing:
var int = setInterval(function() {
if ($("#some-modal").is(":visible"))
$("#some-modal").modal('hide');
else
clearInterval(int);
}.bind(this), 100);
Maybe there is a fix in the bootstrap code possible? Thanks in advance!
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 15 (6 by maintainers)
My answer to issue was to replace the modal with simple in-line spinner, I think it is less invading.
This behavior is too strange and unexpected.
You can simply listen to
hide.bs.modalandhidden.bs.modaland you’ll be sure your modal is hidden. If you prevent theshow.bs.modalevent your modal won’t be visible.