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.

Calling swal.close() does not call the onClose callback

See original GitHub issue

Calling 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();
}

https://jsfiddle.net/ad3quksn/436/

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
rkyokucommented, Feb 15, 2018

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?

2reactions
zenflowcommented, Feb 15, 2018

@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 or swal.clickCancel instead of swal.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.

Read more comments on GitHub >

github_iconTop 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 >

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