sweetalert: Second swal not executed
Hello,
I’ve this sweet-alter call :
var self = this;
swal({
title : $.t('modal.clear.title') || "Etes vous sûr ?",
text : $.t('modal.clear.text') || "Le formulaire sera définitivement perdu !",
type : "warning",
showCancelButton : true,
confirmButtonColor : "#DD6B55",
confirmButtonText : $.t('modal.clear.yes') || "Oui, supprimer",
cancelButtonText : $.t('modal.clear.no') || "Annuler",
closeOnCancel : true
}, function(isConfirm) {
if (isConfirm){
// I Use backbone radio event
self.homePageChannel.trigger('deleteForm', self.currentSelectedForm)
}
});
In the callback I send a an event with backbone radio. At this point all is good.
And in my event response i want to display an another sweet alert like this :
formDeleted : function(result) {
swal({
title : $.t('modal.deleted.title') || 'Formulaire supprimé !',
text : $.t('modal.deleted.text') || 'Votre formulaire a été supprimé avec succès',
type : "success",
});
},
And the second sweet alert doesn’t appear. And i’m sure formDeleted function is executed.
Thanks for your help
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 21 (2 by maintainers)
incase this helps anyone. In my case I was able to sort this out by setting
closeOnCanceland/orcloseOnConfirmtofalse. Thus preventing the closing of the second alert box. The second swal call can set them totrue.I had the same issue, got it solved by added a $timeout on the confirm action (with Angular)
if (isConfirm){ return $timeout(function() { // I Use backbone radio event self.homePageChannel.trigger('deleteForm', self.currentSelectedForm) }, 100); }As of SweetAlert 2.0,
closeOnConfirmandcloseOnCancelare no longer needed to chain SweetAlerts. Just use promises! 😃That is not a correct behavior, we shouldn’t depend on what the value of closeOnCancel and closeOnConfirm is.
SetTimeout can solve the problem after the callback, but I’d like to know more about the cause of the problem.
Had the same problem with my SweetAlert, when the second swal should appear, they don’t, i just get error in my console, solved by including a $timeout in my function.
function(error) { console.log(error); $timeout(function(){ SweetAlert.error('Erro'); },100) }