Google script gmail addon update TextInput value,on change function

六月ゝ 毕业季﹏ 提交于 2019-12-11 01:05:13

问题


I have create simple gmail addon using google script,in that i have struggle here,

how to update textinput value on setOnChangeAction Method ,i have checked the document, i couldn't find any methods

The below code i have tried,

var client_action = CardService.newAction().setFunctionName('clientId_callBack');
CardService.newTextInput()
  .setFieldName("clientId")
  .setTitle("Please enter clinet id")
  .setOnChangeAction(client_action)

function clientId_callBack(e){
  Logger.log("%s",JSON.stringify(e))
  e.formInput.clientId = "updatedValue";
}

Thanks in advance


回答1:


How about this work around? I think that there may be other ways. So please think of this as one of several answers. In this sample script, when the value of foo is inputted, the text input is reconstructed using CardBuilder. When you use this script, as a test, please input foo. This is a very simple snippet, so please modify this for your environment.

Sample script :

function buildAddOn() {
  var card = CardService.newCardBuilder();
  card.setHeader(CardService.newCardHeader().setTitle("Sample"));
  var section = CardService.newCardSection();
  var action = CardService.newAction().setFunctionName('changeValue');
  section.addWidget(CardService.newTextInput().setFieldName("value").setTitle("Input \"foo\" as a value.").setOnChangeAction(action))
  return card.addSection(section).build()
}

function changeValue(e) {
  if (e.formInput.value == "foo") {
    var card = CardService.newCardBuilder();
    card.setHeader(CardService.newCardHeader().setTitle("Changed"));
    var section = CardService.newCardSection();
    var action = CardService.newAction().setFunctionName('getValue1');
    section.addWidget(CardService.newTextInput().setFieldName("value").setTitle("Got \"foo\".").setOnChangeAction(action).setValue("bar"))
    return card.addSection(section).build()
  }
}

If I misunderstand your question, I'm sorry.



来源:https://stackoverflow.com/questions/48705997/google-script-gmail-addon-update-textinput-value-on-change-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!