Class TextInput Stay organized with collections Save and categorize content based on your preferences.
Page Summary
TextInput is an input field widget for accepting text input.
It supports form submission validation to ensure a value is entered when required.
TextInput is available for use in Google Workspace add-ons and Google Chat apps.
Various methods are available to configure the TextInput widget, such as setting the field name, title, hint, and handling changes or suggestions.
A input field widget that accepts text input.
Supports form submission validation. WhenAction.setAllWidgetsAreRequired(allWidgetsAreRequired) is set totrue or this widget is specified throughAction.addRequiredWidget(requiredWidget), the submissionaction is blocked unless a value is entered.
Available for Google Workspace add-ons and Google Chat apps.
consttextInput=CardService.newTextInput().setFieldName('text_input_form_input_key').setTitle('Text input title').setHint('Text input hint');
Methods
| Method | Return type | Brief description |
|---|---|---|
add | Widget | Adds the event action that can be performed on the widget. |
set | Text | Sets the key that identifies this text input in the event object that is generated when thereis a UI interaction. |
set | Text | Sets a hint for the text input. |
set | Text | Sets a data source from Google Workspace applications. |
set | Widget | Sets the unique ID assigned that's used to identify the widget to be mutated. |
set | Text | Sets whether this text input field supports variable insertion. |
set | Text | Sets whether the input text shows on one line or multiple lines. |
set | Text | Sets an action to be performed whenever the text input changes. |
set | Text | Sets the suggestions for autocompletion in the text field. |
set | Text | Sets the callback action to fetch suggestions based on user input for autocompletion. |
set | Text | Sets the title to be shown above the input field. |
set | Text | Sets the validation rule for this widget. |
set | Text | Sets the pre-filled value to be set in the input field. |
set | Widget | Sets the visibility of the widget. |
Detailed documentation
addEventAction(eventAction)
Adds the event action that can be performed on the widget.
Parameters
| Name | Type | Description |
|---|---|---|
event | Event | TheEvent to be added. |
Return
Widget — The Object, for chaining.
setFieldName(fieldName)
Sets the key that identifies this text input in the event object that is generated when thereis a UI interaction. Not visible to the user. Required, must be unique.
Parameters
| Name | Type | Description |
|---|---|---|
field | String | The key that is used to identify this input. |
Return
Text — This object, for chaining.
setHint(hint)
Sets a hint for the text input. Used to give the user extra guidance on what to input. Forexample, a hint could describe formatting ("xxx-xxx-xxxx") for a phone number field.
Parameters
| Name | Type | Description |
|---|---|---|
hint | String | The text hint to display below the input field. This text is always visible. |
Return
Text — This object, for chaining.
setHostAppDataSource(hostAppDataSource)
Sets a data source from Google Workspace applications. Currently supports users and Chatspaces.
Only available for Google Workspace add-ons that extend Google Workspace Studio.
constworkflowDataSource=CardService.newWorkflowDataSource().setIncludeVariables(true);consthostAppDataSource=CardService.newHostAppDataSource().setWorkflowDataSource(workflowDataSource);consttextInput=CardService.newTextInput().setFieldName('text_input_form_input_key').setTitle('Text input title').setHint('Text input hint').setHostAppDataSource(hostAppDataSource);
Parameters
| Name | Type | Description |
|---|---|---|
host | Host | The data source. |
Return
Text — This object, for chaining.
setId(id)
Sets the unique ID assigned that's used to identify the widget to be mutated. Widget mutationis only supported in Add-Ons.
Parameters
| Name | Type | Description |
|---|---|---|
id | String | The id of the widget, with a limit of 64 characters and in format of `[a-zA-Z0-9-]+`. |
Return
Widget — This object, for chaining.
setInputMode(inputMode)
Sets whether this text input field supports variable insertion.
Only available for Google Workspace add-ons that extend Google Workspace Studio.
consttextInput=CardService.newTextInput().setFieldName('text_input_form_input_key').setTitle('Text input title').setInputMode(CardService.TextInputMode.PLAIN_TEXT);
Parameters
| Name | Type | Description |
|---|---|---|
input | Text | The type of input allowed for this text input field, use RICH_TEXT to support variable insertion. |
Return
Text — This object, for chaining.
setMultiline(multiline)
Sets whether the input text shows on one line or multiple lines.
Parameters
| Name | Type | Description |
|---|---|---|
multiline | Boolean | The multiline setting. |
Return
Text — This object, for chaining.
setOnChangeAction(action)
setSuggestions(suggestions)
Sets the suggestions for autocompletion in the text field.
Parameters
| Name | Type | Description |
|---|---|---|
suggestions | Suggestions | The collection of suggestions to use. |
Return
Text — This object, for chaining.
setSuggestionsAction(suggestionsAction)
Sets the callback action to fetch suggestions based on user input for autocompletion. TheAction parameter must specify a callback function that returns aSuggestions object.
constaction=CardService.newAction().setFunctionName('suggestionCallback').setParameters({numSuggestions:3});CardService.newTextInput().setFieldName('option-field').setTitle('Option Selected').setSuggestionsAction(action);// ...functionsuggestionCallback(e){constsuggestions=CardService.newSuggestions();constnumSuggestions=Number.parseInt(e.parameter.numSuggestions);for(leti=1;i<=numSuggestions;i++){suggestions.addSuggestion(`Suggestion${i}`);}returnCardService.newSuggestionsResponseBuilder().setSuggestions(suggestions).build();}
Parameters
| Name | Type | Description |
|---|---|---|
suggestions | Action | The action that fetches suggestions for this input. |
Return
Text — This object, for chaining.
setTitle(title)
Sets the title to be shown above the input field. Required.
Parameters
| Name | Type | Description |
|---|---|---|
title | String | The text label for this input. |
Return
Text — This object, for chaining.
setValidation(validation)
Sets the validation rule for this widget.
constvalidation=CardService.newValidation().setCharacterLimit('10').setType(CardService.InputType.TEXT);constinput=CardService.newTextInput().setFieldName('text_name_xxx1').setTitle('Max 10 characters').setValidation(validation);
Parameters
| Name | Type | Description |
|---|---|---|
validation | Validation | The validation rule for thisText widget. |
Return
Text — This object, for chaining.
setValue(value)
Sets the pre-filled value to be set in the input field.
Parameters
| Name | Type | Description |
|---|---|---|
value | String | The default value placed in the input. It is always represented as a string in the form callback parameters. |
Return
Text — This object, for chaining.
setVisibility(visibility)
Sets the visibility of the widget. The default value is `VISIBLE`.
Parameters
| Name | Type | Description |
|---|---|---|
visibility | Visibility | TheVisibility of the widget. |
Return
Widget — The Object, for chaining.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-03 UTC.