Breaking change in 4.0.0
SweetAlert2 now rejects Promise reject(dismiss)
in cases:
- Cancel button was clicked (dismiss will be
"cancel"
) - Overlay click (
"overlay"
) - Esc press (
"esc"
) - Timer (
"timer"
)
Before 4.0.0 Promise handling:
swal({title: 'Are you sure?', showCancelButton: true}).then(
function(isConfirm) {
if (isConfirm === true) {
// handle Confirm button click
} else if (isConfirm === false) {
// handle Cancel button click
} else {
// Esc, close button or outside click, isConfirm is undefined
}
}
);
Starting with v4.0.0 Promise will be resolved in case of Confirm button was clicked and rejected with dismiss
parameter on all other cases:
swal({title: 'Are you sure?', showCancelButton: true}).then(
function(result) {
// handle Confirm button click
// result is an optional parameter, needed for modals with input
}, function(dismiss) {
// dismiss can be 'cancel', 'overlay', 'esc' or 'timer'
}
);