Class TextInput

TextInput

A input field widget that accepts text input.


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

Methods

MethodReturn typeBrief description
setFieldName(fieldName)TextInputSets the key that identifies this text input in the event object that is generated when there is a UI interaction.
setHint(hint)TextInputSets a hint for the text input.
setMultiline(multiline)TextInputSets whether the input text shows on one line or multiple lines.
setOnChangeAction(action)TextInputSets an action to be performed whenever the text input changes.
setSuggestions(suggestions)TextInputSets the suggestions for autocompletion in the text field.
setSuggestionsAction(suggestionsAction)TextInputSets the callback action to fetch suggestions based on user input for autocompletion.
setTitle(title)TextInputSets the title to be shown above the input field.
setValue(value)TextInputSets 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. E.g., a hint could describe formatting ("xxx-xxx-xxxx") for a phone number field.

Parameters

NameTypeDescription
hintStringthe text hint to display when the input is empty

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
actionActionthe action to take.

Return

TextInput — this object, for chaining.


setSuggestions(suggestions)

Sets the suggestions for autocompletion in the text field.

Parameters

NameTypeDescription
suggestionsSuggestionsthe 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.


 var action = CardService.newAction()
     .setFunctionName('suggestionCallback')
     .setParameters({'numSuggestions': 3});

 CardService.newTextInput()
     .setFieldName('option-field')
     .setTitle('Option Selected')
     .setSuggestionsAction(action);

 // ...

 function suggestionCallback(e) {
   var suggestions = CardService.newSuggestions();
   var numSuggestions = parseInt(e.parameter['numSuggestions']);
   for(var i = 1; i <= numSuggestions; i++) {
     suggestions.addSuggestion('Suggestion ' + i);
   }
   return CardService.newSuggestionsResponseBuilder()
       .setSuggestions(suggestions)
       .build();
 }
 

Parameters

NameTypeDescription
suggestionsActionActionthe 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.


setValue(value)

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

Parameters

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

Return

TextInput — this object, for chaining.

Send feedback about...

Apps Script
Apps Script