question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modal doesn't hide when shortly a show

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
anand7719commented, Mar 23, 2021

My answer to issue was to replace the modal with simple in-line spinner, I think it is less invading.

1reaction
Johann-Scommented, Dec 15, 2017

You can simply listen to hide.bs.modal and hidden.bs.modal and you’ll be sure your modal is hidden. If you prevent the show.bs.modal event your modal won’t be visible.

var $myModal = $('#some-modal')
$myModal.on('shown.bs.modal', function () {
  // modal shown
  setTimeout(function () {
      $myModal.modal('hide')
  }, 1000)
})

$myModal.on('hidden.bs.modal', function () {
  // modal hidden
})

$myModal.modal('show')
Read more comments on GitHub >

github_iconTop Results From Across the Web

Bootstrap modal hide is not working - Stack Overflow
You are using both modal toggling methods: via Javascript and via data attributes. So your click is firing the modal show as your...
Read more >
Modal - Bootstrap
The modal plugin toggles your hidden content on demand, via data attributes or JavaScript. It also adds .modal-open to the <body> to override...
Read more >
How to hide Bootstrap modal with JavaScript? - GeeksforGeeks
This article will tell us how the bootstrap executes when the .modal (modal window) gets closed. At some point of time, the modal...
Read more >
Bootstrap 5 Modal Show, Close, Hide & Toggle - free examples
Modal Backdrop ; hide, Manually hides a modal. Returns to the caller before the modal has actually been hidden (i.e. before the hidden.mdb.modal...
Read more >
Tailwind CSS Modal / Dialog - Free Examples & Tutorial
Set backdrop to static so the modal doesn't close when you click outside of it. Launch static backdrop modal ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found