Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sweetalert2 cancelable timer problem #1321

Closed
teodorsandu opened this issue Dec 5, 2018 · 9 comments
Closed

sweetalert2 cancelable timer problem #1321

teodorsandu opened this issue Dec 5, 2018 · 9 comments
Labels

Comments

@teodorsandu
Copy link

Hi, I posted the question in https://stackoverflow.com/questions/53622723/sweetalert2-cancel-timer-timeout,
also created a pen:
https://codepen.io/teoui/pen/MzdzWy

Thank you.

@gverni
Copy link
Contributor

gverni commented Dec 5, 2018

Hi @teodorsandu, sweetalert2 doesn't expose any API to cancel the timer. If you want to implement a cancellable timer, it's simpler if you create one yourself in the onOpen function and then handle it the way you'd like. You can use the swal.clickCancel() to dismiss the swal, but in this case keep in mind that you will have to create your own dismissal reason check since the swal.DismissReason.timer will not be set in this case.

@limonte
Copy link
Member

limonte commented Dec 5, 2018

Hey @teodorsandu and thanks for the effort you've put into your question and codepen!

Will #1322 help with your use-case?

@teodorsandu
Copy link
Author

Hi @gverni, I'm not that good as javascript to do this :D - anyway @khrismuc gave me a solution in stackoverflow via jsfiddle which I explain in a new codepen in the code's comments.

Basically is not setting timer altogether and instead calling swal.close(); by a setInterval() function.

Hi @limonte - great library by the way and thanks! - yes, a .stopTimer() #1322 method will help!

(should I close this issue?..)

@limonte
Copy link
Member

limonte commented Dec 5, 2018

🎉 This issue has been resolved in version 7.30.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@limonte
Copy link
Member

limonte commented Dec 5, 2018

Live demo of Swal.stopTimer(): https://codepen.io/anon/pen/zMVYKz

@teodorsandu
Copy link
Author

This is awesome 💗 !! Thank you @limonte !! 🙏
while I'm at this it crossed my mind that it would be useful the following methods:

.resumeTimer() - resume timer from where it was when .stopTimer() was called
.increaseTimer(x) - increase (postpone) with x ms the time when the modal will close.
.toggleTimer() - toggle between .stopTimer() and .resumeTimer() ?

@limonte
Copy link
Member

limonte commented Dec 6, 2018

🎉 This issue has been resolved in version 7.31.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@limonte
Copy link
Member

limonte commented Dec 7, 2018

@teodorsandu all requested methods were added, here's the live demo: https://shrouded-request.glitch.me/

@teodorsandu
Copy link
Author

That is simply perfect. Thank you! :) 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants