Creates and opens an alert modal on your mobile app.
When an app user selects an action button in the alert modal, the showAlert()
function returns a Promise that resolves to the alert's result.
Customize the alert modal's title and message, and choose which actions an app user can take when the modal appears.
function showAlert(
title: string,
message: string,
actions: Actions,
): Promise<AlertResult>;
Alert title.
Alert message.
Alert actions.
import wixMobile from "wix-mobile";
/* Sample title value: 'Save changes?'
*
* Sample message value: 'Your message has not been saved'
*
* Sample actions value:
* {
* positive: {
* "label": "Save Now",
* "key": "save"
* },
* negative: {
* "label": "Discard",
* "key": "discard",
* "destructive": true
* },
* neutral: {
* "label": "Remind Me Later",
* "key": "remind"
* }
* }
*/
wixMobile
.showAlert(title, message, actions)
.then((alertResult) => {
const actionKey = alertResult.key;
if (actionKey === "remind") {
console.log("REMIND ME LATER");
}
if (actionKey === "discard") {
console.log("DISCARD");
}
return alertResult;
})
.catch((error) => {
console.error(error);
// Handle the error
});
/* Promise resolves to:
* {
* "key" : "remind"
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.