Search.../

showAlert( )

Creates and opens an alert modal on your mobile app.

Description

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.

Syntax

function showAlert(title: string, message: string, actions: Actions): Promise<AlertResult>

showAlert Parameters

NAME
TYPE
DESCRIPTION
title
string

Alert title.

message
string

Alert message.

actions
Actions

Alert actions.

Returns

Fulfilled - AlertResult.

Return Type:

Promise<AlertResult>
NAME
TYPE
DESCRIPTION
key
string

Unique key for identifying the selected action.

Was this helpful?

Create and open an alert modal

Copy Code
1import wixMobile from 'wix-mobile';
2
3/* Sample title value: 'Save changes?'
4 *
5 * Sample message value: 'Your message has not been saved'
6 *
7 * Sample actions value:
8 * {
9 * positive: {
10 * "label": "Save Now",
11 * "key": "save"
12 * },
13 * negative: {
14 * "label": "Discard",
15 * "key": "discard",
16 * "destructive": true
17 * },
18 * neutral: {
19 * "label": "Remind Me Later",
20 * "key": "remind"
21 * }
22 * }
23 */
24
25wixMobile.showAlert(title, message, actions)
26 .then((alertResult) => {
27 const actionKey = alertResult.key;
28
29 if (actionKey === 'remind') {
30 console.log('REMIND ME LATER')
31 }
32
33 if (actionKey === 'discard') {
34 console.log('DISCARD')
35 }
36
37 return alertResult;
38 })
39 .catch((error) => {
40 console.error(error);
41 // Handle the error
42 });
43
44/* Promise resolves to:
45 * {
46 * "key" : "remind"
47 * }
48 */