Selection input

The SelectionInput widget provides a set of selectable items, such as checkboxes, radio buttons, switches, or a dropdown menu. You can use this widget to collect defined and standardized data from users. To collect undefined data from users, use the TextInput widget instead.

The SelectionInput widget supports suggestions, which help users enter uniform data, and on-change actions, which are Actions that run when a change occurs in a selection input field, such as a user selecting or un-selecting an item.

Chat apps can receive and process the value of selected items during form input events. For details about working with form inputs, see Receive form data.

Examples

This section provides examples of cards that use the SelectionInput widget. The examples use different types of section inputs:

Example 1: checkboxes

The following image displays a dialog that asks the user to specify whether a contact is professional and/or personal with a SelectionInput widget that uses checkboxes:

A dialog featuring a checkbox selection input widget.
Figure 1: A dialog with a checkbox SelectionInput widget.

Here's the card's JSON:

JSON

{
  "cardsV2": [
    {
      "cardId": "exampleCard",
      "card": {
        "sections": [
          {
            "header": "Add new contact",
            "widgets": [
              {
                "selectionInput": {
                  "type": "CHECK_BOX",
                  "label": "Contact type",
                  "name": "contactType",
                  "items": [
                    {
                      "text": "Work",
                      "value": "Work",
                      "selected": false
                    },
                    {
                      "text": "Personal",
                      "value": "Personal",
                      "selected": false
                    }
                  ]
                }
              },
            ]
          }
        ]
      }
    }
  ]
}

Example 2: radio buttons

The following image displays a dialog that asks the user to specify whether a contact is professional or personal with a SelectionInput widget that uses radio buttons:

A dialog featuring a radio selection input widget.
Figure 2: A dialog with a radio SelectionInput widget.

Here's the card's JSON:

JSON

{
  "cardsV2": [
    {
      "cardId": "exampleCard",
      "card": {
        "sections": [
          {
            "header": "Add new contact",
            "widgets": [
              {
                "selectionInput": {
                  "type": "RADIO_BUTTON",
                  "label": "Contact type",
                  "name": "contactType",
                  "items": [
                    {
                      "text": "Work",
                      "value": "Work",
                      "selected": false
                    },
                    {
                      "text": "Personal",
                      "value": "Personal",
                      "selected": false
                    }
                  ]
                }
              },
            ]
          }
        ]
      }
    }
  ]
}

Example 3: switches

The following image displays a dialog that asks the user to specify whether a contact is professional or personal with a SelectionInput widget that uses switches:

A dialog featuring a switch selection input widget.
Figure 3: A dialog with a switch SelectionInput widget.

Here's the card's JSON:

Switches

{
  "cardsV2": [
    {
      "cardId": "exampleCard",
      "card": {
        "sections": [
          {
            "header": "Add new contact",
            "widgets": [
              {
                "selectionInput": {
                  "type": "SWITCH",
                  "label": "Contact type",
                  "name": "contactType",
                  "items": [
                    {
                      "text": "Work",
                      "value": "Work",
                      "selected": false
                    },
                    {
                      "text": "Personal",
                      "value": "Personal",
                      "selected": false
                    }
                  ]
                }
              },
            ]
          }
        ]
      }
    }
  ]
}

The following image displays a dialog that asks the user to specify whether a contact is professional or personal with a SelectionInput widget that uses a dropdown menu:

A dialog featuring a dropdown selection input widget.
Figure 4: A dialog with a dropdown SelectionInput widget.

Here's the card's JSON:

{
  "cardsV2": [
    {
      "cardId": "exampleCard",
      "card": {
        "sections": [
          {
            "header": "Add new contact",
            "widgets": [
              {
                "selectionInput": {
                  "type": "DROPDOWN",
                  "label": "Contact type",
                  "name": "contactType",
                  "items": [
                    {
                      "text": "Work",
                      "value": "Work",
                      "selected": false
                    },
                    {
                      "text": "Personal",
                      "value": "Personal",
                      "selected": false
                    }
                  ]
                }
              },
            ]
          }
        ]
      }
    }
  ]
}

JSON representation and fields

JSON representation
{
  "name": string,
  "label": string,
  "type": enum (SelectionType),
  "items": [
    {
      object (SelectionItem)
    }
  ],
  "onChangeAction": {
    object (Action)
  }
}
Fields
name

string

The name that identifies the selection input in a form input event.

For details about working with form inputs, see Receive form data.

label

string

The text that appears above the selection input field in the user interface.

Specify text that helps the user enter the information your app needs. For example, if users are selecting the urgency of a work ticket from a drop-down menu, the label might be "Urgency" or "Select urgency".

type

enum (SelectionType)

The type of items that are displayed to users in a SelectionInput widget. Selection types support different types of interactions. For example, users can select one or more checkboxes, but they can only select one value from a dropdown menu.

items[]

object (SelectionItem)

An array of selectable items. For example, an array of radio buttons or checkboxes. Supports up to 100 items.

onChangeAction

object (Action)

If specified, the form is submitted when the selection changes. If not specified, you must specify a separate button that submits the form.

For details about working with form inputs, see Receive form data.

SelectionType

Enums
CHECK_BOX A set of checkboxes. Users can select one or more checkboxes.
RADIO_BUTTON A set of radio buttons. Users can select one radio button.
SWITCH A set of switches. Users can turn on one or more switches.
DROPDOWN A dropdown menu. Users can select one item from the menu.

SelectionItem

JSON representation
{
  "text": string,
  "value": string,
  "selected": boolean
}
Fields
text

string

The text that identifies or describes the item to users.

value

string

The value associated with this item. The client should use this as a form input value.

For details about working with form inputs, see Receive form data.

selected

boolean

When true, more than one item is selected. If more than one item is selected for radio buttons and dropdown menus, the first selected item is received and the ones after are ignored.

Action

An action that describes the behavior when the form is submitted. For example, you can invoke an Apps Script script to handle the form. If the action is triggered, the form values are sent to the server.

JSON representation
{
  "function": string,
  "parameters": [
    {
      object (ActionParameter)
    }
  ],
  "loadIndicator": enum (LoadIndicator),
  "persistValues": boolean,
  "interaction": enum (Interaction)
}
Fields
function

string

A custom function to invoke when the containing element is clicked or othrwise activated.

For example usage, see Create interactive cards.

parameters[]

object (ActionParameter)

List of action parameters.

loadIndicator

enum (LoadIndicator)

Specifies the loading indicator that the action displays while making the call to the action.

persistValues

boolean

Indicates whether form values persist after the action. The default value is false.

If true, form values remain after the action is triggered. To let the user make changes while the action is being processed, set LoadIndicator to NONE. For card messages in Chat apps, you must also set the action's ResponseType to UPDATE_MESSAGE and use the same cardId from the card that contained the action.

If false, the form values are cleared when the action is triggered. To prevent the user from making changes while the action is being processed, set LoadIndicator to SPINNER.

interaction

enum (Interaction)

Optional. Required when opening a dialog.

What to do in response to an interaction with a user, such as a user clicking a button in a card message.

If unspecified, the app responds by executing an action —like opening a link or running a function—as normal.

By specifying an interaction, the app can respond in special interactive ways. For example, by setting interaction to OPEN_DIALOG, the app can open a dialog. When specified, a loading indicator isn't shown.

Supported by Chat apps, but not Google Workspace Add-ons. If specified for an add-on, the entire card is stripped and nothing is shown in the client.

ActionParameter

List of string parameters to supply when the action method is invoked. For example, consider three snooze buttons: snooze now, snooze one day, or snooze next week. You might use action method = snooze(), passing the snooze type and snooze time in the list of string parameters.

To learn more, see CommonEventObject.

JSON representation
{
  "key": string,
  "value": string
}
Fields
key

string

The name of the parameter for the action script.

value

string

The value of the parameter.

LoadIndicator

Specifies the loading indicator that the action displays while making the call to the action.

Enums
SPINNER Displays a spinner to indicate that content is loading.
NONE Nothing is displayed.

Interaction

Optional. Required when opening a dialog.

What to do in response to an interaction with a user, such as a user clicking a button in a card message.

If unspecified, the app responds by executing an action —like opening a link or running a function—as normal.

By specifying an interaction, the app can respond in special interactive ways. For example, by setting interaction to OPEN_DIALOG, the app can open a dialog.

When specified, a loading indicator isn't shown.

Supported by Chat apps, but not Google Workspace Add-ons. If specified for an add-on, the entire card is stripped and nothing is shown in the client.

Enums
INTERACTION_UNSPECIFIED Default value. The action executes as normal.
OPEN_DIALOG

Opens a dialog, a windowed, card-based interface that Chat apps use to interact with users.

Only supported by Chat apps in response to button-clicks on card messages.

Not supported by Google Workspace Add-ons. If specified for an add-on, the entire card is stripped and nothing is shown in the client.