Skip to content

Form View

Build a form to collect information from the users.

When the user submit the form, the values can be access in the environment variable with the __ARGS__FORM_VALUE key or the one that you defined in the form name property. The form value is stored as JSON with { "key": "value" } format where the property key is the key you defined in the form field.

interface CommandJSONViewForm {
type: 'form';
name?: string;
title?: string;
description?: string;
cancelBtnText?: string;
submitBtnText?: string;
fields: (CommandJSONViewFormFields | CommandJSONViewFormFields[])[];
}
PropertyTypeDescription
typeformThe view type
fields(CommandJSONViewFormFields | CommandJSONViewFormFields[])[]The form’s fields
name?stringThe key where the form value can be accessed in the environment variable, default is form_value. This will be converted as SCREAMING_SNAKE_CASE with __ARGS__ as the prefix. For example, form_value converted into __ARGS__FORM_VALUE
title?stringThe form’s title
description?stringDescription of the form
cancelBtnText?stringText on the form cancel button
submitBtnText?stringText on the form submit button

Example

console.log(JSON.stringify({
view: {
type: 'form',
title: 'Forms',
fields: [
{
key: 'text-field-1',
type: 'text',
label: 'Text field',
},
{
key: 'textarea',
type: 'text',
multiline: true,
label: 'Textarea',
},
// This will be in the same row
[
{
type: 'toggle',
key: 'toggle1',
label: 'Toggle 1',
},
{
type: 'toggle',
key: 'toggle2',
label: 'Toggle 2',
},
]
]
}
}));

Form Fields

List field you can use to create a form.

type CommandJSONViewFormFields =
| CommandJSONViewFormDate
| CommandJSONViewFormToggle
| CommandJSONViewFormSelect
| CommandJSONViewFormTextField;

Text Field

Displays a form input field.

interface CommandJSONViewFormTextField {
key: string;
type: 'text';
label?: string;
required?: boolean;
multiline?: boolean;
description?: string;
placeholder?: string;
defaultValue?: string;
}
PropertyTypeDescription
typetextThe form field type
keystringThe field unique key
label?stringLabel for the field
required?booleanWhether the user is required to input the field
multiline?booleanWhether the user can input multiple line of text
description?stringDescription of the form field
placeholder?stringText to be displayed when the field has no value
defaultValue?stringDefault value of the field

Example

console.log(JSON.stringify({
view: {
type: 'form',
fields: [
{
key: 'text-field',
type: 'text',
label: 'Text field',
},
{
key: 'textarea',
type: 'text',
multiline: true,
label: 'Textarea',
},
]
}
}));

Date Field

Displays a date form input field.

interface CommandJSONViewFormTextField {
key: string;
type: 'date';
label?: string;
required?: boolean;
multiline?: boolean;
description?: string;
placeholder?: string;
defaultValue?: string;
}
PropertyTypeDescription
typedateThe form field type
keystringThe field unique key
label?stringLabel for the field
required?booleanWhether the user is required to input the field
includeTime?booleanWhether to show the time selection
description?stringDescription of the form field
placeholder?stringText to be displayed when the field has no value
defaultValue?stringDefault value of the field

Example

console.log(JSON.stringify({
view: {
type: 'form',
fields: [
{
key: 'date',
type: 'date',
label: 'Select a date',
},
]
}
}));

Select Field

Displays a list of options for the user to pick from.

interface CommandJSONViewFormTextField {
key: string;
type: 'select';
options: (string | { label: string; value: string })[];
label?: string;
required?: boolean;
description?: string;
placeholder?: string;
defaultValue?: string;
}
PropertyTypeDescription
typeselectThe form field type
keystringThe field unique key
options(string | { label: string; value: string })[]The select’s options
label?stringLabel for the field
required?booleanWhether the user is required to input the field
description?stringDescription of the form field
placeholder?stringText to be displayed when the field has no value
defaultValue?stringDefault value of the field

Example

console.log(JSON.stringify({
view: {
type: 'form',
fields: [
{
key: 'select',
type: 'select',
label: 'Select an option',
options: [
'option-1',
{ label: 'Option 2', value: 'option-2' },
{ label: 'Option 3', value: 'option-3' },
]
},
]
}
}));

Toggle Field

A control that allows the user to toggle between checked and not checked.

interface CommandJSONViewFormTextField {
key: string;
type: 'toggle';
label?: string;
description?: string;
defaultValue?: boolean;
}
PropertyTypeDescription
typetoggleThe form field type
keystringThe field unique key
label?stringLabel for the field
description?stringDescription of the form field
defaultValue?booleanDefault value of the field

Example

console.log(JSON.stringify({
view: {
type: 'form',
fields: [
{
key: 'toggle',
type: 'toggle',
label: 'Airplane Mode',
},
]
}
}));