Handle user interaction with SweetAlert Promises
masterSweetAlert returns a Promise that tracks user interaction.
- If the user clicks the confirm button, the promise resolves to
true(or a specificvalueif configured). - If the alert is dismissed (e.g., clicking outside the modal), the promise resolves to
null.
Dangerous Actions
To warn users before dangerous actions, use these options:
icon: "warning": Shows a warning icon.buttons: true: Adds a cancel button.dangerMode: true: Sets focus to the cancel button and colors the confirm button red.
swal({
title: "Are you sure?",
text: "Once deleted, you will not be able to recover this imaginary file!",
icon: "warning",
buttons: true,
dangerMode: true,
}).then((willDelete) => {
if (willDelete) {
swal("Poof! Your imaginary file has been deleted!", { icon: "success" });
} else {
swal("Your imaginary file is safe!");
}
});