如何插入输入文本框作为单选选项之一?
这是我到目前为止所拥有的:
var urlGroup = CardService.newSelectionInput()
.setType(CardService.SelectionInputType.RADIO_BUTTON)
.setTitle("Please select a link")
.setFieldName("radio_group")
//How do I get a text input field here as one of the radio options
// This is the line I cannot figure out
urlGroup.addItem(** insert input textbox here **)
for (var g = 0; (g < getURLsection.length); g++) {
//shorten long links to fit in card
if (getURLsection[g].length > 21) {
var URLname = getURLsection[g].slice(0, 22) + "..." + getURLsection[g].slice(-5);
} else {
var URLname = getURLsection[g]
}
urlGroup.addItem(URLname, getURLsection[g], false)
}
// create radio button group
var section = CardService.newCardSection()
.addWidget(urlGroup)
关于如何做到这一点有什么想法吗?
最好我想删除单词 Other: 并将其作为教科书中的 .setTitle("enter link here") 。
最佳答案
要在 Google 附加组件中生成文本输入元素,您需要创建 TextInput您稍后需要将其添加到给定部分的小部件对象。
如 addItem 的文档中所述方法,它接收 text
和 value
参数作为字符串,因此您不能在那里使用 TextInput 对象。
作为实现您想要实现的目标的解决方法,您可以使用“otherLink”值创建一个单选组选项:
urlGroup.addItem('Enter link below:', 'otherLink', false);
以及插入单选按钮组部分的文本输入小部件:
var textInput = CardService.newTextInput()
.setFieldName("text_input_form_input_key")
.setTitle("enter link here")
// create radio button group section with text input
var section = CardService.newCardSection()
.addWidget(urlGroup)
.addWidget(textInput)
这样,文本输入将出现在单选按钮下方,如果单选按钮组中选定的值为“otherLink”,您就可以使用在输入文本中输入的值(链接)。
关于javascript - Gmail 插件使用文本输入创建单选组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60805309/