Creating the swal
is an asynchronous process, meaning you cannot just return a synchronous result from it.
If you look at the docs, you can see that swal
returns a promise, so you can take advantage of that and pass the success and fail callbacks:
ConfirmationMessage = function(msg) {
return swal({ ... }); // <--- return the swal call which returns a promise
};
ConfirmationMessage('message to show')
.then(function() {
// success happened
}, function(dismiss) {
// fail happened
// dismiss can be 'cancel', 'overlay', 'close', and 'timer'
if (dismiss === 'cancel') {
// user cancelled
}
});