Close sweetalert2 seem not working
See original GitHub issueI am not sure if I missed something but I can’t close sweetalert2, I found a workaround by manually removing from DOM.
Because with turbolinks when an alert toast is open, and I switch page, and return back, for a second I can still see sweetalert2, from turbolinks cache.
So I am trying to close sweetalert before turbolinks cache page using event:
document.addEventListener("turbolinks:before-cache", function() {
Swal.close();
})
But this doesn’t work, I can still see sweetalert cached.
I found below workaround which works fine:
document.addEventListener("turbolinks:before-cache", function() {
document.documentElement.classList.remove('swal2-toast-shown', 'swal2-shown')
document.querySelector('.swal2-container').remove()
})
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
aurelia - Sweetalert2 won't close - Stack Overflow
I'm using: ... you're right! just to add to this, the problem is in file material-dashboard.css or in plugins_sweetalert2.scss. ... I'm unable to ......
Read more >SweetAlert2 - a beautiful, responsive, customizable and ...
A beautiful, responsive, customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes.
Read more >Sweetalert not working - Laracasts
I'm using Sweetalert on Laravel 5.1, when I click on delete button the alert button appears but after 2 or 3 seconds it...
Read more >SweetAlert2 (Advance version of SweetAlert) - GeeksforGeeks
There is an independent dependency that needs to be installed to work with SweetAlert2. Syntax: function SweetAlert2() { const fireAlert = () => ......
Read more >[SweetAlert2] Tried on OS11... Don't seems to work.
Had the same problem and had this component to be uploaded on forge on my backlog for a while now. It implements confirmation...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think I understand the issue. The closing isn’t happening instantly because there’s the closing animation which is
0.2s
long.What if you unset the animation and then close a toast? Something like this:
@limonte I notice a warning in console:
It’s just a warning so maybe I could ignore it? But this happen when using above solution with Turbolinks.