Class TextInput

  • 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.

TextInput

A input field widget that accepts text input.

Supports form submission validation. When Action.setAllWidgetsAreRequired(allWidgetsAreRequired) is set to true or this widget is specified through Action.addRequiredWidget(requiredWidget) , the submission action 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

MethodReturn typeBrief description
setFieldName(fieldName) TextInput Sets the key that identifies this text input in the event object that is generated when there is a UI interaction.
setHint(hint) TextInput Sets a hint for the text input.
setHostAppDataSource(hostAppDataSource) TextInput Sets a data source from Google Workspace applications.
setMultiline(multiline) TextInput Sets whether the input text shows on one line or multiple lines.
setOnChangeAction(action) TextInput Sets an action to be performed whenever the text input changes.
setSuggestions(suggestions) TextInput Sets the suggestions for autocompletion in the text field.
setSuggestionsAction(suggestionsAction) TextInput Sets the callback action to fetch suggestions based on user input for autocompletion.
setTitle(title) TextInput Sets the title to be shown above the input field.
setValidation(validation) TextInput Sets the validation rule for this widget.
setValue(value) TextInput Sets the pre-filled value to be set in the input field.

Detailed documentation

setFieldName(fieldName)

Sets the key that identifies this text input in the event object that is generated when there is a UI interaction. Not visible to the user. Required, must be unique.

Parameters

NameTypeDescription
fieldNameStringThe key that is used to identify this input.

Return

TextInput — This object, for chaining.


setHint(hint)

Sets a hint for the text input. Used to give the user extra guidance on what to input. For example, a hint could describe formatting ("xxx-xxx-xxxx") for a phone number field.

Parameters

NameTypeDescription
hintStringThe text hint to display below the input field. This text is always visible.

Return

TextInput — This object, for chaining.


setHostAppDataSource(hostAppDataSource)

Sets a data source from Google Workspace applications. Currently supports users and Chat spaces.

Only available through the Gemini Alpha program for Google Workspace add-ons that extend Google Workspace Flows.

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

NameTypeDescription
hostAppDataSourceHostAppDataSource The data source.

Return

TextInput — This object, for chaining.


setMultiline(multiline)

Sets whether the input text shows on one line or multiple lines.

Parameters

NameTypeDescription
multilineBooleanThe multiline setting.

Return

TextInput — This object, for chaining.


setOnChangeAction(action)

Sets an action to be performed whenever the text input changes.

Parameters

NameTypeDescription
actionAction The action to take.

Return

TextInput — This object, for chaining.


setSuggestions(suggestions)

Sets the suggestions for autocompletion in the text field.

Parameters

NameTypeDescription
suggestionsSuggestions The collection of suggestions to use.

Return

TextInput — This object, for chaining.


setSuggestionsAction(suggestionsAction)

Sets the callback action to fetch suggestions based on user input for autocompletion. The Action parameter must specify a callback function that returns a SuggestionsResponse 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

NameTypeDescription
suggestionsActionAction The action that fetches suggestions for this input.

Return

TextInput — This object, for chaining.


setTitle(title)

Sets the title to be shown above the input field. Required.

Parameters

NameTypeDescription
titleStringThe text label for this input.

Return

TextInput — 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

NameTypeDescription
validationValidation The validation rule for this TextInput widget.

Return

TextInput — This object, for chaining.


setValue(value)

Sets the pre-filled value to be set in the input field.

Parameters

NameTypeDescription
valueStringThe default value placed in the input. It is always represented as a string in the form callback parameters.

Return

TextInput — This object, for chaining.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年10月28日 UTC.