接受文字輸入的輸入欄位小工具。
支援表單提交驗證。如果 Action.setAllWidgetsAreRequired(allWidgetsAreRequired) 設為 true 或透過 Action.addRequiredWidget(requiredWidget) 指定這個小工具,除非輸入值,否則系統會封鎖提交動作。
適用於 Google Workspace 外掛程式和 Google Chat 應用程式。
const textInput = CardService.newTextInput() .setFieldName('text_input_form_input_key') .setTitle('Text input title') .setHint('Text input hint');
方法
| 方法 | 傳回類型 | 簡短說明 |
|---|---|---|
add | Widget | 新增可在小工具上執行的事件動作。 |
set | Text | 設定在發生 UI 互動時產生的事件物件中,用於識別這個文字輸入內容的鍵。 |
set | Text | 設定文字輸入的提示。 |
set | Text | 設定 Google Workspace 應用程式的資料來源。 |
set | Widget | 設定指派的專屬 ID,用於識別要變動的小工具。 |
set | Text | 設定這個文字輸入欄位是否支援插入變數。 |
set | Text | 設定輸入文字顯示在一行或多行。 |
set | Text | 設定在文字輸入內容變更時執行的動作。 |
set | Text | 設定文字欄位的自動完成建議。 |
set | Text | 設定回呼動作,根據使用者輸入內容的自動完成內容擷取建議。 |
set | Text | 設定顯示在輸入欄位上方的標題。 |
set | Text | 為這個小工具設定驗證規則。 |
set | Text | 設定要在輸入欄位中設定的預填值。 |
set | Widget | 設定小工具的顯示設定。 |
內容詳盡的說明文件
addEventAction(eventAction)
setFieldName(fieldName)
設定在發生 UI 互動時產生的事件物件中,用於識別這個文字輸入內容的鍵。使用者不會看到這項資訊。必要欄位,不得重複。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
field | String | 用來識別這個輸入內容的金鑰。 |
回攻員
TextInput - 這個物件,用於鏈結。
setHint(hint)
設定文字輸入的提示。用於為使用者提供額外的輸入指引。舉例來說,提示可以說明電話號碼欄位的格式 (「xxx-xxx-xxxx」)。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
hint | String | 顯示在輸入欄位下方的文字提示。這段文字會一直顯示。 |
回攻員
TextInput - 這個物件,用於鏈結。
setHostAppDataSource(hostAppDataSource)
設定 Google Workspace 應用程式的資料來源。目前支援使用者和 Chat 空間。
僅適用於擴充 Google Workspace Studio 的 Google Workspace 外掛程式。
const workflowDataSource = CardService.newWorkflowDataSource().setIncludeVariables(true); const hostAppDataSource = CardService.newHostAppDataSource().setWorkflowDataSource(workflowDataSource); const textInput = CardService.newTextInput() .setFieldName('text_input_form_input_key') .setTitle('Text input title') .setHint('Text input hint') .setHostAppDataSource(hostAppDataSource);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
host | Host | 資料來源。 |
回攻員
TextInput - 這個物件,用於鏈結。
setId(id)
設定指派的專屬 ID,用於識別要變動的小工具。外掛程式僅支援小工具變動。