Skip to content

Alert

Display system alert or action sheet

Alert is used to display modal dialogs to users, supporting buttons, text fields and other interactive elements.

Use Alert to:

Note

Not available in Widget

Examples

javascript
let alert = new Alert();
alert.title = "Confirm";
alert.message = "Are you sure you want to proceed?";
alert.addAction("OK");
alert.addCancelAction("Cancel");
let index = await alert.present();
javascript
let alert = new Alert();
alert.title = "Login";
alert.addTextField("Username");
alert.addSecureTextField("Password");
alert.addAction("Login");
await alert.present();
let username = alert.textFieldValue(0);
let password = alert.textFieldValue(1);

Properties

title

  • Type: String

Alert title

The main title text displayed at the top of the alert.

javascript
alert.title = "Title"

message

  • Type: String

Alert message

The detailed description text displayed below the title.

javascript
alert.message = "Description"

Methods

addAction

Add a standard action button

Adds a button with default style.

typescript
addAction(title): void
  • title - The button text

Example:

javascript
alert.addAction("OK")

addDestructiveAction

Add a destructive action button

Adds a red-colored button for destructive actions like delete.

typescript
addDestructiveAction(title): void
  • title - The button text

Example:

javascript
alert.addDestructiveAction("Delete")

addCancelAction

Add a cancel button

Adds a cancel button. An alert can only have one cancel button; adding another will replace the previous one. The cancel button always returns index -1.

typescript
addCancelAction(title): void
  • title - The button text

Example:

javascript
alert.addCancelAction("Cancel")

addTextField

Add a text field

Adds a plain text input field to the alert. Only available in alert style, not supported in sheet style.

typescript
addTextField(placeholder, text): Promise
  • placeholder - Placeholder text for the field
  • text - Default text value

Returns: TextField object

Example:

javascript
alert.addTextField("Enter text", "Default")

addSecureTextField

Add a secure text field

Adds a password input field where text is hidden. Only available in alert style.

typescript
addSecureTextField(placeholder, text): Promise
  • placeholder - Placeholder text for the field
  • text - Default text value

Returns: TextField object

Example:

javascript
alert.addSecureTextField("Password")

textFieldValue

Get text field value

Gets the current value of the text field at the specified index. Index starts from 0.

typescript
textFieldValue(index): string
  • index - Text field index, starting from 0

Returns: The text value of the field

Example:

javascript
let value = alert.textFieldValue(0)

present

Present the alert

Same as presentAlert(_:), displays as a modal dialog.

typescript
present(callback): void
  • callback - Callback after user interaction

Returns: Promise that resolves to the tapped button index (-1 for cancel)

Example:

javascript
let index = await alert.present()

presentAlert

Present as alert dialog

Displays a modal dialog in the center of the screen.

typescript
presentAlert(callback): void
  • callback - Callback after user interaction

Returns: Promise that resolves to the tapped button index (-1 for cancel)

Example:

javascript
let index = await alert.presentAlert()

presentSheet

Present as action sheet

Displays an action sheet from the bottom of the screen. Shows as popover on iPad. Note: Sheet style does not support text fields.

typescript
presentSheet(callback): void
  • callback - Callback after user interaction

Returns: Promise that resolves to the tapped button index (-1 for cancel)

Example:

javascript
let index = await alert.presentSheet()