showAlert( )


Creates and opens an alert modal on your mobile app.

developer preview tag

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.

Method Declaration
Copy
function showAlert(
  title: string,
  message: string,
  actions: Actions,
): Promise<AlertResult>;
Method Parameters
titlestringRequired

Alert title.


messagestringRequired

Alert message.


actionsActionsRequired

Alert actions.

Returns
Return Type:Promise<AlertResult>
Create and open an alert modal
JavaScript
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" * } */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?