【问题标题】:Gmail Add-on Create Radio Group with Text InputGmail 插件使用文本输入创建单选组
【发布时间】:2020-07-03 10:18:04
【问题描述】:

我正在使用动态创建的广播组开发 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)

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

【问题讨论】:

    标签: javascript google-apps-script gmail-api gmail-addons gsuite-addons


    【解决方案1】:

    要在 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”,您可以使用输入文本中输入的值(链接)。

    【讨论】:

    • 该死的,我认为这是可能的。您的解决方法很好,但是我担心用户会忘记单击“其他链接”单选按钮。除非我将其设为默认选择。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-05
    • 1970-01-01
    • 2015-04-27
    • 2017-04-04
    • 1970-01-01
    • 1970-01-01
    • 2019-06-21
    相关资源
    最近更新 更多