calling swal.close() or swal.closeModal() from a separate function does not work
See original GitHub issueHi 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:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Sorry, but I’m closing this. Please put more effort into making question/jsfiddle in future.
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. 😃