Calling swal.close() does not call the onClose callback
See original GitHub issueCalling swal.close()
does not call the onClose
callback. It does work, though, when calling swal.clickCancel()
.
swal({
onClose: () => {
console.log('not being called');
}
});
if (swal.isVisible()) {
swal.close();
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:8 (5 by maintainers)
Top Results From Across the Web
How to listen for when sweet alert closes - Stack Overflow
Its called passing a reference of the function to call when onClose gets fired of swal. Make a little change like this:
Read more >SweetAlert2 - a beautiful, responsive, customizable and ...
The timer ran out, and the alert closed automatically. timer. If a popup is dismissed by Swal.close(), the Promise will be resolved with...
Read more >Guides - SweetAlert
After importing the files into your application, you can call the swal function (make sure it's called after the DOM has loaded!) swal("Hello...
Read more >Vue - tell parent to run method on close of child. - Laracasts
I have a form to create a new Sales Order. If the Customer is not showing up, I want the user to open...
Read more >SweetModal: Examples
Replace alert() , confirm() , prompt() and many plugins with style and elegance ... onClose, function() {}, Callback running when the modal is...
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
IMHO, it should always provide an information regarding what triggered it (cancel button, close button, click on overlay, validation, whatever).
It does not cost anything (I think) to do it, and it provides information that may be of value in some cases.
What do you think?
@RenaudParis Thanks for opening this issue, with reproduction
Hmm. Yeah, that behavior seems wrong.
We should probably restrain from fixing it in this major though, since it’s a breaking change and might cause issues in some projects.
As a temporary workaround, maybe use
swal.clickConfirm
orswal.clickCancel
instead ofswal.close
. You can use those even if the buttons aren’t visible.Slightly off-topic Open question - What would you expect to happen with the current swal’s Promise when you use
swal.close
? Currently it’s left in a pending state.