# Titanium.UI.AlertDialog

> An alert dialog is a modal view that includes an optional title, a message and buttons, positioned in the middle of the display.

- Source: https://titaniumsdk.com/docs/sdk/13.3.0/Titanium.UI.AlertDialog
- Titanium SDK version: 13.3.0
- Kind: view
- Platforms: Android, iPhone, iPad, macOS
- Since: Titanium SDK 0.8
- Extends: Titanium.UI.View
- Inheritance: Titanium.UI.View > Titanium.Proxy

| Android | iOS |
| ------- | --- |
| ![Android](./alertdialog_android.png) | ![iOS](./alertdialog_ios.png) |

An alert dialog is created using [Titanium.UI.createAlertDialog](https://titaniumsdk.com/docs/sdk/Titanium.UI.md#createAlertDialog) or **`<AlertDialog>`** Alloy element.

Although this dialog always appears in the middle of the display (not touching the edges),
other aspects of its aesthetics and the way the user interacts with it are different for each
platform, as described below.

#### Android

On Android, the default alert dialog displays text information, via a title and message, without
any buttons. As the user can use the system hardware `back` button to dismiss it, a button is
optional.

Buttons are shown if the `buttonNames` property is defined, and are rendered horizontally below
the message.

To create a custom layout, a view may be added and, in turn, a hierarchy of views added to that
child view.

#### iOS

On iOS, the default alert dialog displays text information, via a title and message, with
a single button to allow it to be dismissed.

Buttons are defined using the `buttonNames` property and are rendered vertically below
the message. Alert dialogs are automatically cancelled when the application is
paused/suspended. This behavior can be avoided by setting `persistent` property on alert dialog
to be `true`.

The `style` property can be used to allow the user to enter plain text,
obscured text or login identifier and password. Entered values can be captured with listening
`cancel` event.

Starting at Titanium SDK 5.1.0, you can also specify the `placeholder`, `keyboardType` and `returnKeyType`
properties when using the alert dialog style [Titanium.UI.iOS.AlertDialogStyle.PLAIN_TEXT_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#PLAIN_TEXT_INPUT) or
[Titanium.UI.iOS.AlertDialogStyle.SECURE_TEXT_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#SECURE_TEXT_INPUT).
When using the alert dialog style [Titanium.UI.iOS.AlertDialogStyle.LOGIN_AND_PASSWORD_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#LOGIN_AND_PASSWORD_INPUT), you can
specify the `loginPlaceholder`, `loginKeyboardType` and `loginReturnKeyType` properties for the login field,
as well as the `passwordPlaceholder`, `passwordKeyboardType` and `passwordReturnKeyType` properties for the password field.

#### Global Alias

A global method `alert()` is aliased to this object, and can be invoked with a single message.
For example

``` js
alert('this is a message');
```

This will generate an alert with a title of "Alert" and an "OK" button.

#### Caveats

Multiple alerts should not be shown at once.

The `title` and `ok` properties cannot be changed while the alert dialog is being displayed. On
Android only, you can change the `message` property while the alert dialog is being displayed.

## Example: Single-button Alert Dialog (using alias)

Create a single-button alert dialog using the global `alert()` alias.

``` js
var win = Ti.UI.createWindow({
  title: 'Click window to test',
  backgroundColor: 'white'
});

win.addEventListener('click', function(e) {
  alert('The file has been deleted');
});
win.open();
```

## Example: Single-button Alert Dialog (standard)

Create a single-button alert dialog, without explicitly defining it using the `buttonNames`
property, which is invoked when the app window is clicked.

``` js
var win = Ti.UI.createWindow({
  title: 'Click window to test',
  backgroundColor: 'white'
});

win.addEventListener('click', function(e) {
  var dialog = Ti.UI.createAlertDialog({
    message: 'The file has been deleted',
    ok: 'Okay',
    title: 'File Deleted'
  });
  dialog.show();
});
win.open();
```

## Example: Three-button Alert Dialog

Create a three-button alert dialog, which is invoked when the app window is clicked.
Output a message to the log when the cancel button is clicked.

``` js
var win = Ti.UI.createWindow({
  title: 'Click window to test',
  backgroundColor: 'white'
});
win.addEventListener('click', function(e) {
  var dialog = Ti.UI.createAlertDialog({
    cancel: 1,
    buttonNames: ['Confirm', 'Cancel', 'Help'],
    message: 'Would you like to delete the file?',
    title: 'Delete'
  });
  dialog.addEventListener('click', function(e) {
    if (e.index === e.source.cancel) {
      Ti.API.info('The cancel button was clicked');
    }
    Ti.API.info('e.cancel: ' + e.cancel);
    Ti.API.info('e.source.cancel: ' + e.source.cancel);
    Ti.API.info('e.index: ' + e.index);
  });
  dialog.show();
});
win.open();
```

## Example: Alert Dialog with Plain Text Input

Create an alert dialog and allow the user enter plain text, which is invoked when the
app window is clicked.
Output entered text value to the log when the OK button is clicked.

``` js
var win = Ti.UI.createWindow({
  title: 'Click window to test'
});
win.addEventListener('click', function(e) {
  var dialog = Ti.UI.createAlertDialog({
    title: 'Enter text',
    style: Ti.UI.iOS.AlertDialogStyle.PLAIN_TEXT_INPUT,
    buttonNames: ['OK']
  });
  dialog.addEventListener('click', function(e) {
    Ti.API.info('e.text: ' + e.text);
  });
  dialog.show();
});
win.open();
```

## Example: Alloy XML Markup

Previous three-button alert dialog example as an Alloy view.

alertdialog.xml:
``` xml
<Alloy>
    <Window id="win" onClick="showDialog" title="Click window to test" backgroundColor="white"
        exitOnClose="true" fullscreen="false" >

        <AlertDialog id="dialog" onClick="doClick" title="Delete"
            message="Would you like to delete the file?" cancel="1">

            <!-- The ButtonNames tag sets the buttonNames property. -->
            <ButtonNames>
                <ButtonName>Confirm</ButtonName>
                <ButtonName>Cancel</ButtonName>
                <ButtonName>Help</ButtonName>
            </ButtonNames>
        </AlertDialog>
    </Window>
</Alloy>
```

alertdialog.js:
``` js
function showDialog() {
    $.dialog.show();
}

function doClick(e) {
    Ti.API.info('e.text: ' + e.text);
}

$.win.open();
```

## Properties

### androidView

- Type: Titanium.UI.View
- Platforms: Android

View to load inside the message area, to create a custom layout.

In an Alloy application you can specify this property with either an `<AndroidView/>` or
`<View/>` element inside the `<AlertDialog/>` element, for example:

``` xml
<Alloy>
    <AlertDialog onClick="doClick" title="Delete"
        message="Would you like to delete the file?" cancel="1">

        <!--  Add View or AndroidView for the androidView property  -->
        <View platform="android">
            <Label color="red" text="Warning!  This change is permanent and you cannot undo it!" />
        </View>

        <ButtonNames>
            <ButtonName>Confirm</ButtonName>
            <ButtonName>Cancel</ButtonName>
        </ButtonNames>
    </AlertDialog>
</Alloy>
```

### buttonClickRequired

- Type: Boolean
- Platforms: Android
- Since: Titanium SDK 7.5.0
- Default: `false on Android`

Setting this to true requires the end-user to click a dialog button to close the dialog.

Set to true to prevent the dialog from being dismissed via back navigation or tapping outside of the dialog.
This requires the end-user to click on one of the dialog buttons provided by property buttonNames. Note that
if the dialog does not have any buttons, then the dialog can only be closed programmatically via the hide() method.

### buttonNames

- Type: Array<String>
- Platforms: Android, iPhone, iPad, macOS
- Default: `No buttons (Android), Single "OK" button (iOS)`

Name of each button to create.

On iOS, a button will automatically be created if none are explicitly defined, because
without it users would be unable to dismiss the dialog. Conversely, a dialog with no
buttons may be created on Android, as the hardware `back` button may be used instead.

A maximum of 3 buttons is supported on Android.

Alloy applications can specify this property with a `<ButtonNames>` element containing
one or more `<ButtonName>` elements (see example).

``` xml
<Alloy>
    <AlertDialog id="dialog" onClick="doClick" title="Decide!" message="Do you really want to do that?" cancel="1">
        <ButtonNames>
            <ButtonName>Confirm</ButtonName>
            <ButtonName>Cancel</ButtonName>
            <ButtonName>Help</ButtonName>
        </ButtonNames>
    </AlertDialog>
</Alloy>
```

### cancel

- Type: Number
- Platforms: Android, iPhone, iPad, macOS
- Default: `undefined (Android), -1 (iOS)`

Index to define the cancel button.

On iOS, set to `-1` to disable the cancel option.

### canceledOnTouchOutside

- Type: Boolean
- Platforms: Android
- Since: Titanium SDK 6.0.0
- Default: `true on Android`

When this is set to `true`, the dialog is canceled when touched outside the window's bounds.

### destructive

- Type: Number
- Platforms: iPhone, iPad, macOS
- Since: Titanium SDK 3.5.0
- Default: `-1`

Index to define the destructive button.

Setting this property to -1 disables this option.

### hintText

- Type: String
- Platforms: iPhone, iPad, macOS
- Since: Titanium SDK 5.4.0

Hint text of the text field inside the dialog.

Note that this property is only available if dialog `style` property is defined as
[Titanium.UI.iOS.AlertDialogStyle.PLAIN_TEXT_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#PLAIN_TEXT_INPUT) or
[Titanium.UI.iOS.AlertDialogStyle.SECURE_TEXT_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#SECURE_TEXT_INPUT).

### hinttextid

- Type: String
- Platforms: iPhone, iPad, macOS
- Since: Titanium SDK 6.2.0

Key identifying a string from the locale file to use for the
[hintText](https://titaniumsdk.com/docs/sdk/Titanium.UI.AlertDialog.md#hintText) property.

Only one of `hintText` or `hinttextid` should be specified.

### keyboardAppearance

- Type: Number
- Platforms: iPhone, iPad, macOS
- Since: Titanium SDK 5.2.0
- Default: `<Titanium.UI.KEYBOARD_APPEARANCE_DEFAULT>`

Keyboard appearance to be displayed when the text field inside the dialog is focused.

Note that this property is only available if dialog `style` property is defined as
[Titanium.UI.iOS.AlertDialogStyle.PLAIN_TEXT_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#PLAIN_TEXT_INPUT) or
[Titanium.UI.iOS.AlertDialogStyle.SECURE_TEXT_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#SECURE_TEXT_INPUT).

Accepts: `Titanium.UI.KEYBOARD_APPEARANCE_DARK`, `Titanium.UI.KEYBOARD_APPEARANCE_DEFAULT`, `Titanium.UI.KEYBOARD_APPEARANCE_LIGHT`

### keyboardType

- Type: Number
- Platforms: iPhone, iPad, macOS
- Since: Titanium SDK 5.1.0
- Default: `<Titanium.UI.KEYBOARD_TYPE_DEFAULT>`

Keyboard type to display when this text field inside the dialog is focused.

Note that this property is only available if dialog `style` property is defined as
[Titanium.UI.iOS.AlertDialogStyle.PLAIN_TEXT_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#PLAIN_TEXT_INPUT) or
[Titanium.UI.iOS.AlertDialogStyle.SECURE_TEXT_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#SECURE_TEXT_INPUT).

Accepts: `Titanium.UI.KEYBOARD_TYPE_ASCII`, `Titanium.UI.KEYBOARD_TYPE_DECIMAL_PAD`, `Titanium.UI.KEYBOARD_TYPE_DEFAULT`, `Titanium.UI.KEYBOARD_TYPE_EMAIL`, `Titanium.UI.KEYBOARD_TYPE_NAMEPHONE_PAD`, `Titanium.UI.KEYBOARD_TYPE_NUMBERS_PUNCTUATION`, `Titanium.UI.KEYBOARD_TYPE_NUMBER_PAD`, `Titanium.UI.KEYBOARD_TYPE_PHONE_PAD`, `Titanium.UI.KEYBOARD_TYPE_TWITTER`, `Titanium.UI.KEYBOARD_TYPE_URL`, `Titanium.UI.KEYBOARD_TYPE_WEBSEARCH`

### loginHintText

- Type: String
- Platforms: iPhone, iPad, macOS
- Since: Titanium SDK 5.4.0

Hint text of the login text field inside the dialog.

Note that this property is only available if dialog `style` property is defined as
[Titanium.UI.iOS.AlertDialogStyle.LOGIN_AND_PASSWORD_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#LOGIN_AND_PASSWORD_INPUT).

### loginhinttextid

- Type: String
- Platforms: iPhone, iPad, macOS
- Since: Titanium SDK 6.2.0

Key identifying a string from the locale file to use for the
[loginHintText](https://titaniumsdk.com/docs/sdk/Titanium.UI.AlertDialog.md#loginHintText) property.

Only one of `loginHintText` or `loginhinttextid` should be specified.

### loginKeyboardType

- Type: Number
- Platforms: Android, iPhone, iPad, macOS
- Since: Titanium SDK 5.1.0
- Default: `<Titanium.UI.KEYBOARD_DEFAULT>`

Keyboard type to display when this text field inside the dialog is focused.

Note that this property is only available if dialog `style` property is defined as
[Titanium.UI.iOS.AlertDialogStyle.LOGIN_AND_PASSWORD_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#LOGIN_AND_PASSWORD_INPUT).

Accepts: `Titanium.UI.KEYBOARD_APPEARANCE_DARK`, `Titanium.UI.KEYBOARD_APPEARANCE_DEFAULT`, `Titanium.UI.KEYBOARD_APPEARANCE_LIGHT`, `Titanium.UI.KEYBOARD_TYPE_ASCII`, `Titanium.UI.KEYBOARD_TYPE_DECIMAL_PAD`, `Titanium.UI.KEYBOARD_TYPE_DEFAULT`, `Titanium.UI.KEYBOARD_TYPE_EMAIL`, `Titanium.UI.KEYBOARD_TYPE_NAMEPHONE_PAD`, `Titanium.UI.KEYBOARD_TYPE_NUMBERS_PUNCTUATION`, `Titanium.UI.KEYBOARD_TYPE_NUMBER_PAD`, `Titanium.UI.KEYBOARD_TYPE_PHONE_PAD`, `Titanium.UI.KEYBOARD_TYPE_TWITTER`, `Titanium.UI.KEYBOARD_TYPE_URL`, `Titanium.UI.KEYBOARD_TYPE_WEBSEARCH`

### loginPlaceholder

- Type: String
- Platforms: iPhone, iPad, macOS
- Since: Titanium SDK 5.1.0
- DEPRECATED since 5.4.0. Use [Titanium.UI.AlertDialog.loginHintText](Titanium.UI.AlertDialog.loginHintText) instead.

Placeholder of the login text field inside the dialog.

Note that this property is only available if dialog `style` property is defined as
[Titanium.UI.iOS.AlertDialogStyle.LOGIN_AND_PASSWORD_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#LOGIN_AND_PASSWORD_INPUT).

### loginReturnKeyType

- Type: Number
- Platforms: Android, iPhone, iPad, macOS
- Since: Titanium SDK 5.1.0
- Default: `<Titanium.UI.RETURNKEY_NEXT>`

Specifies the text to display on the keyboard `Return` key when this field is focused.

Note that this property is only available if dialog `style` property is defined as
[Titanium.UI.iOS.AlertDialogStyle.LOGIN_AND_PASSWORD_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#LOGIN_AND_PASSWORD_INPUT).

Accepts: `Titanium.UI.RETURNKEY_CONTINUE`, `Titanium.UI.RETURNKEY_DEFAULT`, `Titanium.UI.RETURNKEY_DONE`, `Titanium.UI.RETURNKEY_EMERGENCY_CALL`, `Titanium.UI.RETURNKEY_GO`, `Titanium.UI.RETURNKEY_GOOGLE`, `Titanium.UI.RETURNKEY_JOIN`, `Titanium.UI.RETURNKEY_NEXT`, `Titanium.UI.RETURNKEY_ROUTE`, `Titanium.UI.RETURNKEY_SEARCH`, `Titanium.UI.RETURNKEY_SEND`, `Titanium.UI.RETURNKEY_YAHOO`

### loginValue

- Type: String
- Platforms: iPhone, iPad, macOS
- Since: Titanium SDK 6.1.0

Value of the login text field inside the dialog.

Note that this property is only available if dialog `style` property is defined as
[Titanium.UI.iOS.AlertDialogStyle.LOGIN_AND_PASSWORD_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#LOGIN_AND_PASSWORD_INPUT).

### message

- Type: String
- Platforms: Android, iPhone, iPad, macOS

Dialog message.

### messageid

- Type: String
- Platforms: Android, iPhone, iPad, macOS

Key identifying a string in the locale file to use for the message text.

### ok

- Type: String
- Platforms: Android, iPhone, iPad, macOS

Text for the `OK` button.

This property is useful when only one button is required, as it negates the need to define
the `buttonNames` property. If `buttonNames` is defined, this property is ignored.

### okid

- Type: String
- Platforms: iPhone, iPad, macOS

Key identifying a string in the locale file to use for the `ok` text.

If `buttonNames` is defined, this property is ignored.

### passwordHintText

- Type: String
- Platforms: iPhone, iPad, macOS
- Since: Titanium SDK 5.4.0

Hint text of the password text field inside the dialog.

Note that this property is only available if dialog `style` property is defined as
[Titanium.UI.iOS.AlertDialogStyle.LOGIN_AND_PASSWORD_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#LOGIN_AND_PASSWORD_INPUT).

### passwordhinttextid

- Type: String
- Platforms: iPhone, iPad, macOS
- Since: Titanium SDK 6.2.0

Key identifying a string from the locale file to use for the
[passwordHintText](https://titaniumsdk.com/docs/sdk/Titanium.UI.AlertDialog.md#passwordHintText) property.

Only one of `passwordHintText` or `hinttextid` should be specified.

### passwordKeyboardType

- Type: Number
- Platforms: Android, iPhone, iPad, macOS
- Since: Titanium SDK 5.1.0
- Default: `<Titanium.UI.KEYBOARD_DEFAULT>`

Keyboard type to display when this text field inside the dialog is focused.

Note that this property is only available if dialog `style` property is defined as
[Titanium.UI.iOS.AlertDialogStyle.LOGIN_AND_PASSWORD_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#LOGIN_AND_PASSWORD_INPUT).

Accepts: `Titanium.UI.KEYBOARD_APPEARANCE_DARK`, `Titanium.UI.KEYBOARD_APPEARANCE_DEFAULT`, `Titanium.UI.KEYBOARD_APPEARANCE_LIGHT`, `Titanium.UI.KEYBOARD_TYPE_ASCII`, `Titanium.UI.KEYBOARD_TYPE_DECIMAL_PAD`, `Titanium.UI.KEYBOARD_TYPE_DEFAULT`, `Titanium.UI.KEYBOARD_TYPE_EMAIL`, `Titanium.UI.KEYBOARD_TYPE_NAMEPHONE_PAD`, `Titanium.UI.KEYBOARD_TYPE_NUMBERS_PUNCTUATION`, `Titanium.UI.KEYBOARD_TYPE_NUMBER_PAD`, `Titanium.UI.KEYBOARD_TYPE_PHONE_PAD`, `Titanium.UI.KEYBOARD_TYPE_TWITTER`, `Titanium.UI.KEYBOARD_TYPE_URL`, `Titanium.UI.KEYBOARD_TYPE_WEBSEARCH`

### passwordPlaceholder

- Type: String
- Platforms: iPhone, iPad, macOS
- Since: Titanium SDK 5.1.0
- DEPRECATED since 5.4.0. Use [Titanium.UI.AlertDialog.passwordHintText](Titanium.UI.AlertDialog.passwordHintText) instead.

Placeholder of the password text field inside the dialog.

Note that this property is only available if dialog `style` property is defined as
[Titanium.UI.iOS.AlertDialogStyle.LOGIN_AND_PASSWORD_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#LOGIN_AND_PASSWORD_INPUT).

### passwordReturnKeyType

- Type: Number
- Platforms: Android, iPhone, iPad, macOS
- Since: Titanium SDK 5.1.0
- Default: `<Titanium.UI.RETURNKEY_DONE>`

Specifies the text to display on the keyboard `Return` key when this field is focused.

Note that this property is only available if dialog `style` property is defined as
[Titanium.UI.iOS.AlertDialogStyle.LOGIN_AND_PASSWORD_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#LOGIN_AND_PASSWORD_INPUT).

Accepts: `Titanium.UI.RETURNKEY_CONTINUE`, `Titanium.UI.RETURNKEY_DEFAULT`, `Titanium.UI.RETURNKEY_DONE`, `Titanium.UI.RETURNKEY_EMERGENCY_CALL`, `Titanium.UI.RETURNKEY_GO`, `Titanium.UI.RETURNKEY_GOOGLE`, `Titanium.UI.RETURNKEY_JOIN`, `Titanium.UI.RETURNKEY_NEXT`, `Titanium.UI.RETURNKEY_ROUTE`, `Titanium.UI.RETURNKEY_SEARCH`, `Titanium.UI.RETURNKEY_SEND`, `Titanium.UI.RETURNKEY_YAHOO`

### passwordValue

- Type: String
- Platforms: iPhone, iPad, macOS
- Since: Titanium SDK 6.1.0

Value of the password text field inside the dialog.

Note that this property is only available if dialog `style` property is defined as
[Titanium.UI.iOS.AlertDialogStyle.LOGIN_AND_PASSWORD_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#LOGIN_AND_PASSWORD_INPUT).

### persistent

- Type: Boolean
- Platforms: Android, iPhone, iPad, macOS
- Since: Titanium SDK 3.0.0
- Default: `false on iOS, true on Android`

Boolean value indicating if the alert dialog should only be cancelled by user gesture or by hide method.

This property is useful to ensure that the alert dialog will not be ignored
by the user when the application is paused/suspended.

### placeholder

- Type: String
- Platforms: iPhone, iPad, macOS
- Since: Titanium SDK 5.1.0
- DEPRECATED since 5.4.0. Use [Titanium.UI.AlertDialog.hintText](Titanium.UI.AlertDialog.hintText) instead.

Placeholder of the text field inside the dialog.

Note that this property is only available if dialog `style` property is defined as
[Titanium.UI.iOS.AlertDialogStyle.PLAIN_TEXT_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#PLAIN_TEXT_INPUT) or
[Titanium.UI.iOS.AlertDialogStyle.SECURE_TEXT_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#SECURE_TEXT_INPUT).

### preferred

- Type: Number
- Platforms: iPhone, iPad, macOS
- Since: Titanium SDK 6.0.0
- Default: `-1`

Index to define the preferred button.

When you specify a preferred action, the alert dialog highlights the text of that
action to give it emphasis. (If the alert also contains a cancel button, the preferred
action receives the highlighting instead of the cancel button.) If the iOS device is
connected to a physical keyboard, pressing the Return key triggers the preferred action.

Note that this property is only available on iOS 9 or above.

### returnKeyType

- Type: Number
- Platforms: iPhone, iPad, macOS
- Since: Titanium SDK 5.1.0
- Default: `<Titanium.UI.RETURNKEY_DEFAULT>`

Specifies the text to display on the keyboard `Return` key when this field is focused.

Note that this property is only available if dialog `style` property is defined as
[Titanium.UI.iOS.AlertDialogStyle.PLAIN_TEXT_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#PLAIN_TEXT_INPUT) or
[Titanium.UI.iOS.AlertDialogStyle.SECURE_TEXT_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#SECURE_TEXT_INPUT).

Accepts: `Titanium.UI.RETURNKEY_CONTINUE`, `Titanium.UI.RETURNKEY_DEFAULT`, `Titanium.UI.RETURNKEY_DONE`, `Titanium.UI.RETURNKEY_EMERGENCY_CALL`, `Titanium.UI.RETURNKEY_GO`, `Titanium.UI.RETURNKEY_GOOGLE`, `Titanium.UI.RETURNKEY_JOIN`, `Titanium.UI.RETURNKEY_NEXT`, `Titanium.UI.RETURNKEY_ROUTE`, `Titanium.UI.RETURNKEY_SEARCH`, `Titanium.UI.RETURNKEY_SEND`, `Titanium.UI.RETURNKEY_YAHOO`

### severity

- Type: Number
- Platforms: iPhone, iPad, macOS
- Since: Titanium SDK 12.0.0
- Requires: iOS 16.0+
- Default: `<Titanium.UI.iOS.ALERT_SEVERITY_DEFAULT>`

Indicates the severity of the alert in apps built with Mac Catalyst.

This property defines the severity options used by the severity property
of UIAlertController. In apps built with Mac Catalyst, the severity
determines the style of the presented alert. A [Titanium.UI.iOS.ALERT_SEVERITY_CRITICAL](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.md#ALERT_SEVERITY_CRITICAL)
alert appears with a caution icon, and an alert with a [Titanium.UI.iOS.ALERT_SEVERITY_DEFAULT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.md#ALERT_SEVERITY_DEFAULT)
severity doesn’t. UIKit ignores the alert severity on iOS.

You should only use the [Titanium.UI.iOS.ALERT_SEVERITY_CRITICAL](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.md#ALERT_SEVERITY_CRITICAL) severity if an alert truly requires
special attention from the user.

For more information, see the [Human Interface Guidelines](https://developer.apple.com/design/human-interface-guidelines/macos/windows-and-views/alerts/) on alerts.

Accepts: `Titanium.UI.iOS.ALERT_SEVERITY_CRITICAL`, `Titanium.UI.iOS.ALERT_SEVERITY_DEFAULT`

### style

- Type: Number
- Platforms: iPhone, iPad, macOS
- Since: Titanium SDK 3.0.0
- Default: `<Titanium.UI.iOS.AlertDialogStyle.DEFAULT>`

The style for the alert dialog.

Style of the alert dialog, specified using one of the constants from
[Titanium.UI.iOS.AlertDialogStyle](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md). Using styles other than default one can break
your dialog layout if more than two buttons used. All styles can handle up to two
buttons comfortably, except for default style can handle up to six buttons when `title`
and `message` is empty or not given. Note that this property is only available on
iOS SDK 5 or above.

### tintColor

- Type: String | Titanium.UI.Color
- Platforms: iPhone, iPad, macOS
- Since: Titanium SDK 6.2.0

The tint-color of the dialog.

This property is a direct correspondent of the `tintColor` property of
UIView on iOS. For a dialog, it will tint the color of it's buttons.
For information about color values, see the "Colors" section of [Titanium.UI](https://titaniumsdk.com/docs/sdk/Titanium.UI.md).

### title

- Type: String
- Platforms: Android, iPhone, iPad, macOS

Title of the dialog.

If not set, a dialog with no title bar will be created.

### titleid

- Type: String
- Platforms: Android, iPhone, iPad, macOS

Key identifying a string in the locale file to use for the title text.

### value

- Type: String
- Platforms: iPhone, iPad, macOS
- Since: Titanium SDK 6.1.0

Value of the text field inside the dialog.

Note that this property is only available if dialog `style` property is defined as
[Titanium.UI.iOS.AlertDialogStyle.PLAIN_TEXT_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#PLAIN_TEXT_INPUT) or
[Titanium.UI.iOS.AlertDialogStyle.SECURE_TEXT_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#SECURE_TEXT_INPUT).

## Methods

### hide

- Platforms: Android, iPhone, iPad, macOS

Hides this dialog.

### show

- Platforms: Android, iPhone, iPad, macOS

Shows this dialog.

## Events

### click

- Platforms: Android, iPhone, iPad, macOS

Fired when a button in the dialog is clicked.

Event properties:

- `cancel` (Boolean | Number): Boolean type on Android; Number on iOS. On Android, indicates whether the cancel button was clicked, in which case returns `true`. On iOS, the value of the [cancel](https://titaniumsdk.com/docs/sdk/Titanium.UI.AlertDialog.md#cancel) property is returned, if defined, or `-1` otherwise. Also note that the cancel button may not be used on the iPad, because iOS will internally decide whether or not to show it in the current context (e.g. in a popover). See the `Three-button Alert Dialog` example for a cross-platform workaround for this parity issue.
- `index` (Number): Index of the button that was clicked.
- `login` (String): Value of login field if dialog `style` property is defined as [Titanium.UI.iOS.AlertDialogStyle.LOGIN_AND_PASSWORD_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#LOGIN_AND_PASSWORD_INPUT).
- `password` (String): Value of password field if dialog `style` property is defined as [Titanium.UI.iOS.AlertDialogStyle.LOGIN_AND_PASSWORD_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#LOGIN_AND_PASSWORD_INPUT).
- `text` (String): Value of text field if dialog `style` property is defined as [Titanium.UI.iOS.AlertDialogStyle.PLAIN_TEXT_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#PLAIN_TEXT_INPUT) or [Titanium.UI.iOS.AlertDialogStyle.SECURE_TEXT_INPUT](https://titaniumsdk.com/docs/sdk/Titanium.UI.iOS.AlertDialogStyle.md#SECURE_TEXT_INPUT).

## Inherited members

34 members are inherited. Each is documented on the type that declares it.

- [Titanium.Proxy](https://titaniumsdk.com/docs/sdk/13.3.0/Titanium.Proxy.md): `addEventListener`, `apiName`, `applyProperties`, `bubbleParent`, `fireEvent`, `lifecycleContainer`, `removeEventListener`
- [Titanium.UI.View](https://titaniumsdk.com/docs/sdk/13.3.0/Titanium.UI.View.md): `accessibilityDisableLongPress`, `clearMotionEffects`, `elevation`, `filterTouchesWhenObscured`, `getViewById`, `hiddenBehavior`, `horizontalMotionEffect`, `id`, `insertAt`, `keepHardwareMode`, `previewContext`, `replaceAt`, `rotate`, `rotation`, `rotationX`, `rotationY`, `scaleX`, `scaleY`, `stopAnimation`, `tooltip`, `touchFeedback`, `touchFeedbackColor`, `transitionName`, `translationX`, `translationY`, `translationZ`, `verticalMotionEffect`

---

- This corpus documents Titanium SDK 13.4.1. Anything here that does not name a version describes 13.4.1.
- Titanium is maintained by TiDev. The Appcelerator toolchain is retired: there is no `appc` CLI, no Appcelerator Studio and no hosted build service. The supported CLI is `titanium` on npm, invoked as `ti`.

