Class TextInput

Text Input

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.

 const 
  
 textInput 
  
 = 
  
 CardService 
 . 
 newTextInput 
 () 
  
 . 
 setFieldName 
 ( 
 'text_input_form_input_key' 
 ) 
  
 . 
 setTitle 
 ( 
 'Text input title' 
 ) 
  
 . 
 setHint 
 ( 
 'Text input hint' 
 ); 

Methods

Method Return type Brief description
Text Input Sets the key that identifies this text input in the event object that is generated when there is a UI interaction.
Text Input Sets a hint for the text input.
Text Input Sets whether the input text shows on one line or multiple lines.
Text Input Sets an action to be performed whenever the text input changes.
Text Input Sets the suggestions for autocompletion in the text field.
Text Input Sets the callback action to fetch suggestions based on user input for autocompletion.
Text Input Sets the title to be shown above the input field.
Text Input Sets the validation rule for this widget.
Text Input Sets the pre-filled value to be set in the input field.

Detailed documentation

set Field Name(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

Name Type Description
field Name
String The key that is used to identify this input.

Return

Text Input — This object, for chaining.


set Hint(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

Name Type Description
hint
String The text hint to display below the input field. This text is always visible.

Return

Text Input — This object, for chaining.


set Multiline(multiline)

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

Parameters

Name Type Description
multiline
Boolean The multiline setting.

Return

Text Input — This object, for chaining.


set On Change Action(action)

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

Parameters

Name Type Description
action
Action The action to take.

Return

Text Input — This object, for chaining.


set Suggestions(suggestions)

Sets the suggestions for autocompletion in the text field.

Parameters

Name Type Description
suggestions
Suggestions The collection of suggestions to use.

Return

Text Input — This object, for chaining.


set Suggestions Action(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 Suggestions Response object.

 const 
  
 action 
  
 = 
  
 CardService 
 . 
 newAction 
 () 
  
 . 
 setFunctionName 
 ( 
 'suggestionCallback' 
 ) 
  
 . 
 setParameters 
 ({ 
 numSuggestions 
 : 
  
 3 
 }); 
 CardService 
 . 
 newTextInput 
 () 
  
 . 
 setFieldName 
 ( 
 'option-field' 
 ) 
  
 . 
 setTitle 
 ( 
 'Option Selected' 
 ) 
  
 . 
 setSuggestionsAction 
 ( 
 action 
 ); 
 // ... 
 function 
  
 suggestionCallback 
 ( 
 e 
 ) 
  
 { 
  
 const 
  
 suggestions 
  
 = 
  
 CardService 
 . 
 newSuggestions 
 (); 
  
 const 
  
 numSuggestions 
  
 = 
  
 Number 
 . 
 parseInt 
 ( 
 e 
 . 
 parameter 
 . 
 numSuggestions 
 ); 
  
 for 
  
 ( 
 let 
  
 i 
  
 = 
  
 1 
 ; 
  
 i 
  
< = 
  
 numSuggestions 
 ; 
  
 i 
 ++ 
 ) 
  
 { 
  
 suggestions 
 . 
 addSuggestion 
 ( 
 `Suggestion 
 ${ 
 i 
 } 
 ` 
 ); 
  
 } 
  
 return 
  
 CardService 
 . 
 newSuggestionsResponseBuilder 
 () 
  
 . 
 setSuggestions 
 ( 
 suggestions 
 ) 
  
 . 
 build 
 (); 
 } 

Parameters

Name Type Description
suggestions Action
Action The action that fetches suggestions for this input.

Return

Text Input — This object, for chaining.


set Title(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 Input — This object, for chaining.


set Validation(validation)

Sets the validation rule for this widget.

 const 
  
 validation 
  
 = 
  
 CardService 
 . 
 newValidation 
 (). 
 setCharacterLimit 
 ( 
 '10' 
 ). 
 setType 
 ( 
  
 CardService 
 . 
 InputType 
 . 
 TEXT 
 ); 
 const 
  
 input 
  
 = 
  
 CardService 
 . 
 newTextInput 
 () 
  
 . 
 setFieldName 
 ( 
 'text_name_xxx1' 
 ) 
  
 . 
 setTitle 
 ( 
 'Max 10 characters' 
 ) 
  
 . 
 setValidation 
 ( 
 validation 
 ); 

Parameters

Name Type Description
validation
Validation The validation rule for this Text Input widget.

Return

Text Input — This object, for chaining.


set Value(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 Input — This object, for chaining.

Create a Mobile Website
View Site in Mobile | Classic
Share by: