Form View
Form View allows to request some data from the user. When the form is submitted, the command will receive all values in the respective parameters.
The delivery method depends on the type of your command. For Local Commands, the form data is sent using stdin, and for Cloud Commands, it's sent using a GET or POST request.

Form

Property CommandResponse.view of type Form allows to show a custom form in the Command Bar.
    type: "form"
    fields: An array of FormField objects. By default, each field will be displayed in a separate row. If you want some fields to be displayed in the same row – put them in a nested array, the available space will be evenly split between them. See examples below for more details.
    title: Optional. Title of the form shown above it.
    submitLabel: Optional. Text label for the submit button.
    cancelLabel: Optional. Text label for the cancel button.
    method: Optional. "get" or "post" (default). HTTP request method that will be used to submit the form. This is only relevant to Cloud Commands.
Simple form to order a drink
Multiple fields on the same row
1
{
2
"view": {
3
"type": "form",
4
"title": "Order Drink",
5
"submitLabel": "Order",
6
"fields": [
7
{
8
"type": "text",
9
"id": "name",
10
"label": "Your Name"
11
},
12
{
13
"type": "select",
14
"id": "drink",
15
"label": "Drink",
16
"options": [
17
"Cappuccino",
18
"Latte",
19
"Green Tea",
20
"Coke"
21
]
22
}
23
]
24
}
25
}
Copied!
1
{
2
"view": {
3
"type": "form",
4
"fields": [
5
[
6
{
7
"type": "text",
8
"id": "firstName",
9
"label": "First Name"
10
},
11
{
12
"type": "text",
13
"id": "lastName",
14
"label": "Last Name"
15
},
16
{
17
"type": "toggle",
18
"id": "subscribe",
19
"label": "Subscribe to Newsletter"
20
}
21
],
22
{
23
"type": "textarea",
24
"id": "notes",
25
"label": "Notes"
26
}
27
]
28
}
29
}
Copied!

FormField

Property CommandResponse.view.fields defines an array of fields in the Form View. There are multiple different form field types that allow creating sophisticated forms.
1
type FormField = TextField | ToggleField | SelectField | DateField;
Copied!

TextField

A plain-text input, similar to the HTML <input/> tag, defines a field where a user can enter free-form data.
    type: "text"
    id: ID of the field. Must be unique in the Form view.
    label: Label for the field.
    required: Optional, true or false. Whether this field is required.
    defaultValue: Optional. The initial text value for this field.
    error: Optional. If set, shows an error message under the field.
    helpText: Optional. A Markdown text which will be displayed under the field.
    placeholder: Optional. Placeholder for this field, displayed inside the field in gray.
    multiline: Optional, true or false. Whether the field should be displayed as a large textarea.
Single line text field
Large textarea field
1
{
2
"view": {
3
"type": "form",
4
"fields": [
5
{
6
"type": "text",
7
"id": "name",
8
"label": "Name",
9
"required": true,
10
"defaultValue": "Steve",
11
"placeholder": "Tell us your name"
12
}
13
]
14
}
15
}
Copied!
1
{
2
"view": {
3
"type": "form",
4
"fields": [
5
{
6
"type": "text",
7
"id": "notes",
8
"label": "Your Notes",
9
"placeholder": "What is on your mind?",
10
"multiline": true
11
}
12
]
13
}
14
}
Copied!

ToggleField

Defines a field that allows the user to enable or disable something.
    type: "toggle"
    id: ID of the field. Must be unique in the Form View.
    label: Label for the field.
    required: Optional, true or false. Whether this field is required.
    defaultValue: Optional, true or false. The default value for this field.
    error: Optional. If set, shows an error message under the field.
    helpText: Optional. A Markdown text which will be displayed under the field.
Simple toggle field
1
{
2
"view": {
3
"type": "form",
4
"fields": [
5
{
6
"type": "toggle",
7
"id": "subscribe",
8
"label": "Subscribe to Newsletter",
9
"defaultValue": true
10
}
11
]
12
}
13
}
Copied!

DateField

Defines a field which lets the user easily select a date from a calendar style UI.
    type: "date"
    id: ID of the field. Must be unique in the Form View.
    label: Label for the field.
    required: Optional, true or false. Whether this field is required.
    defaultValue: Optional. Default value for this field as a Date string.
    error: Optional. If set, shows an error message under the field.
    helpText: Optional. A Markdown text which will be displayed under the field.
    timeSelect: Optional, true or false (default). Whether the field allows selecting the time too.
Simple date field
1
{
2
"view": {
3
"type": "form",
4
"title": "When is your birthday?",
5
"fields": [
6
{
7
"type": "date",
8
"id": "dateOfBirth",
9
"label": "Your Date of Birth"
10
}
11
]
12
}
13
}
Copied!

SelectField

Defines a field that allows the user to select one or multiple options.
    type: "select"
    id: ID of the field. Must be unique in the Form View.
    label: Label for the field.
    options: A list of strings or SelectOption objects that a user can select from.
    required: Optional, true or false. Whether this field is required.
    defaultValue: Optional. Default value for this field. If the field allows selecting multiple values (see multiple), an array of strings can be provided.
    error: Optional. If set, shows an error message under the field.
    helpText: Optional. A Markdown text which will be displayed under the field.
    multiple: Optional, true or false. Whether the field allow selecting single or multiple options.
    placeholder: Optional. Placeholder of the field, shown inside in gray.

SelectOption

Allows to customize options for SelectField.
    label: Label for the option.
    value: Value of the option.
Select field that allows to pick only one option
Select field with custom options
Select field that allows to pick multiple options
1
{
2
"view": {
3
"type": "form",
4
"fields": [
5
{
6
"type": "select",
7
"id": "country",
8
"label": "Country of Residence",
9
"options": [
10
"Ukraine",
11
"Spain",
12
"Germany"
13
]
14
}
15
]
16
}
17
}
Copied!
1
{
2
"view": {
3
"type": "form",
4
"fields": [
5
{
6
"type": "select",
7
"id": "country",
8
"label": "Country of Residence",
9
"options": [
10
{
11
"value": "ukr",
12
"label": "Ukraine"
13
},
14
{
15
"value": "s",
16
"label": "Spain"
17
},
18
{
19
"value": "g",
20
"label": "Germany"
21
}
22
]
23
}
24
]
25
}
26
}
Copied!
1
{
2
"view": {
3
"type": "form",
4
"fields": [
5
{
6
"type": "select",
7
"id": "country",
8
"label": "Where do you want to travel to?",
9
"multiple": true,
10
"placeholder": "Select Countries",
11
"options": [
12
"Ukraine",
13
"Spain",
14
"Germany"
15
]
16
}
17
]
18
}
19
}
Copied!
Last modified 6d ago