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() or swal.closeModal() from a separate function does not work

See original GitHub issue

Hi limonte,

I’m a long time sweetalert user, from the original, to yours, and I use it extensively in many of my projects - so I wanted to say thank you for all of your hard work. I upgraded to the latest version in order to fix some bugs, and it seemed to break the functionality I had of calling swal.close() or swal.closeModal() from a separate function.

function add_something() {
   
   htmlString =  '<div class="add_something_header"> <i class="fa fa-plus fa-gray"></i></div>'+                
                '<div class="help_holder">'+
                '<div id="as_body" class="as_body"></div></div>'+
                '<div id="add_something_footer" class="add_something_footer"><div class="footer_buttons_holder"><div onclick="close_swal()" class="footer_cancel_button">CANCEL</div></div></div>';
                   
  swal({
    html  : htmlString,
    width : 1100,
    showConfirmButton: false,
    showCancelButton: false,
    allowOutsideClick: false
    },
    function(isConfirm) {
      if (isConfirm) {
      } else { 
      }
  });
}

`

Clicking on the above CANCEL button should run the function close_swal(), and it does, but the swal-related code inside does not trigger.

function close_swal() { console.log("Closing swal..."); swal.close(); //also tried swal.closeModal(); }

This worked fine in the older version of sweetalert2 that I was using (from 2015), but not in 6.3.8.

If I try to mimic the close functionality by running swal.clickCancel(); , I get an error in sweetalert2.js:

// Clicked 'cancel' } else if (targetedCancel && sweetAlert.isVisible()) { sweetAlert.closeModal(params.onClose); reject('cancel'); //on this line }

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

18reactions
limontecommented, Feb 7, 2017

Sorry, but I’m closing this. Please put more effort into making question/jsfiddle in future.

4reactions
lordterrincommented, Feb 7, 2017

No worries - I think it may be something on my end as even simple swals are not working. Sorry to waste your time - and still, thank you so much for your hard work on this project. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to close sweet alert on ajax request completion
You can use SweetAlert.close() to close the sweetalert in angular. ... swal does not work with sync function (ex. get ), you need...
Read more >
Creating Pretty Popup Messages Using SweetAlert2 - Code
All you have to do is call the Swal.fire() function. Just make sure that the function is called after the DOM has loaded....
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 >
sweetalert2 - npm
Resets settings to their default value. swal.close() or swal.closeModal(), Close the currently open SweetAlert2 modal programmatically. swal.
Read more >
Guides - SweetAlert
Showing an alert. After importing the files into your application, you can call the swal function (make sure it's called after the DOM...
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