0

我正在使用动态创建的无线电组开发 Gmail 插件,例如: 在此处输入图像描述

如何插入输入文本框作为单选选项之一?

这是我到目前为止所拥有的:

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)

关于如何做到这一点的任何想法?
最好我想删除“其他: ”这个词,并将其作为教科书中的 .setTitle("enter link here") 。

4

1 回答 1

0

要在 Google 的附加组件中生成文本输入元素,您需要创建一个TextInput小部件对象,稍后您需要将其添加到给定部分。

如addItem方法的文档中所述,它接收textvalue参数作为字符串,因此您不能在那里使用 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”,您可以使用输入文本中输入的值(链接)。

于 2020-03-24T10:44:17.193 回答