Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Prompt

Prompts allow the creation and display of custom dialogs to request information or confirmation from the user.

Example

var p = Prompt.create();

p.title = "Hello";
p.message = "World!";

p.addTextField("textFieldName", "Label", "");

p.addDatePicker("myDate", "Start date", new Date(), {
  "mode": "date"
});
p.addButton("First");
p.addButton("Second");

var didSelect = p.show();

var textFieldContents = p.fieldValues["textFieldName"];
var startDate = p.fieldValues["myDate"];

if (p.buttonPressed == "First") {
  // do something
}

Hierarchy

  • Prompt

Index

Properties

buttonPressed

buttonPressed: string

After the show() method is called, this property will contain the name of the button selected by the user.

fieldValues

fieldValues: object

After the show() method is called, this property will contain values from any fields added to the prompt. The dictionary keys will be the names of the fields as passed in when they were created, and the value will be the current contents of that field. They type of data depends on the type of field.

Type declaration

  • [x: string]: any

isCancellable

isCancellable: boolean

If true, a "Cancel" button will be included in the dialog. Defaults to true. If the user selects the cancel button, the show() method will return false. If false, no cancel button will be displayed and the user must select one of the button name options.

message

message: string

A longer message explaining the purpose of the dialog, if needed.

title

title: string

Methods

addButton

  • addButton(name: string, value?: string, isDefault?: boolean): void
  • Add a button to the array of buttons to be displayed. All buttons should be created before calling show().

    Parameters

    • name: string
    • Optional value: string

      only needed to associate a different value than will be displayed in the button. For example, if you call prompt.addButton("First Button", 1), after calling prompt.show() if that button is pressed, the prompt.buttonPressed will contain the number value 1.

    • Optional isDefault: boolean

      used to specify a single button which will be pinned to the bottom of the prompt and respond to cmd + return as the default button. If only one button is added to a prompt, it is assumed to be the default.

    Returns void

addDatePicker

  • addDatePicker(name: string, label: string, initialDate: Date, options?: object): void
  • Add a date and/or time picker to the prompt, with the arguments as below. The fieldValues entry for this will be a date object.

    Parameters

    • name: string

      Identifier for the field. This will be used as the key in the fieldValues dictionary to access the contents of the field after calling show().

    • label: string

      User-friendly text label to place next to the field.

    • initialDate: Date

      The initial date to selected for the field. Minimum and maximum values should be defined in options.

    • Optional options: object

      A dictionary of options for configuring the text field. See the site for full descriptions of the options.

      • Optional maximumDate?: Date
      • Optional minimumDate?: Date
      • Optional minuteInterval?: number
      • Optional mode?: "date" | "time" | "dateAndTime"

    Returns void

addLabel

  • addLabel(name: string, label: string, options?: object): void
  • Add an information text label to the prompt.

    Parameters

    • name: string

      Identifier for the field.

    • label: string

      The text of the label.

    • Optional options: object

      A dictionary of options for configuring the text field.

      • Optional textSize?: "body" | "caption" | "headline"

    Returns void

addPasswordField

  • addPasswordField(name: string, label: string, initialValue: string): void
  • Same as addTextField, but the input field will be password masked.

    Parameters

    • name: string
    • label: string
    • initialValue: string

    Returns void

addPicker

  • addPicker(name: string, label: string, columns: string[][], selectedRows: number[]): void
  • Add a picker to the prompt, with the arguments as below. Picker can contain multiple rows. The fieldValues entry for this will be a array of selected index values object.

    Parameters

    • name: string

      Identifier for the field. This will be used as the key in the fieldValues dictionary to access the contents of the field after calling show().

    • label: string

      User-friendly text label to place next to the field.

    • columns: string[][]

      The values to display in the picker. Should be an array containing arrays of string values, each sub-array representing a column in the picker. Example two column picker: [["Item 1", "Item 2"],["Column 2 Item 1", "Column 2 Item 2"]]

    • selectedRows: number[]

      Array of zero-based index values to set the initial selected row in each column.

    Returns void

addSelect

  • addSelect(name: string, label: string, values: string[], selectedValues: string[], allowMultiple: boolean): void
  • Add a select control. Returns an array of string values in fieldValues.

    Parameters

    • name: string

      Identifier for the field. This will be used as the key in the fieldValues dictionary to access the contents of the field after calling show().

    • label: string

      User-friendly text label to place next to the field.

    • values: string[]

      The array of string values that will be available to select.

    • selectedValues: string[]

      Array of string values that should be initially selected when the prompt is displayed. All values in this array should match values in the values array.

    • allowMultiple: boolean

      If false, selecting a value will deselect all other values. If true, the user may select multiple items.

    Returns void

addSwitch

  • addSwitch(name: string, label: string, initialValue: boolean): void
  • Add an on/off toggle switch. The fieldValues entry for this item will be a boolean indicating whether the switch was on.

    Parameters

    • name: string

      Identifier for the field. This will be used as the key in the fieldValues dictionary to access the contents of the field after calling show().

    • label: string

      User-friendly text label to place next to the field.

    • initialValue: boolean

      indicate if the switch should be on or off when initially displayed.

    Returns void

addTextField

  • addTextField(name: string, label: string, initialText: string, options?: object): void
  • Add a text input field to the prompt

    Parameters

    • name: string

      Identifier for the field. This will be used as the key in the fieldValues dictionary to access the contents of the field after calling show().

    • label: string

      User-friendly text label to place next to the field.

    • initialText: string

      The initial text contents for the field.

    • Optional options: object

      A dictionary of options for configuring the text field. See the site for full descriptions of the options.

      • Optional autocapitalization?: capitalizationTypes
      • Optional autocorrect?: boolean
      • Optional keyboard?: keyboardTypes
      • Optional placeholder?: string
      • Optional wantsFocus?: boolean

    Returns void

addTextView

  • addTextView(name: string, label: string, initialText: string, options?: object): void
  • Add a text input field to the prompt

    Parameters

    • name: string

      Identifier for the field. This will be used as the key in the fieldValues dictionary to access the contents of the field after calling show().

    • label: string

      User-friendly text label to place next to the field.

    • initialText: string

      The initial text contents for the field.

    • Optional options: object

      A dictionary of options for configuring the text field. See the site for full descriptions of the options.

      • Optional autocapitalization?: capitalizationTypes
      • Optional autocorrect?: boolean
      • Optional height?: number
      • Optional keyboard?: keyboardTypes
      • Optional wantsFocus?: boolean

    Returns void

show

  • show(): boolean
  • Displays the prompt. Returns true if the user selected one of the buttons in the buttons array, false if the user selected the "Cancel" button. After the dialog has been shown, the buttonPressed property will contain the name of the button selected by the user.

    Returns boolean

Static create

Generated using TypeDoc