6

我将用一个例子来展示我的问题:

我有一个按钮。TextInputFields单击后,它会根据附加组件中的创建邮件草稿。我有一个验证功能,它可以判断字段是否填写正确。

如果我想以某种方式通知用户错误的字段,我必须创建一个通知或使用错误信息重建卡。这些动作可以正常返回Action,但不能用 a composeAction(因为composeAction必须用构建的草稿返回),所以我必须向composeAction按钮注册 a 和一个简单的动作。

当我点击这种按钮时,只有一个动作执行,另一个什么也不做。

关于我如何尝试实现的一些代码:

section.addWidget(CardService.newTextButton()
  .setText('Validate and Create')
  .setComposeAction(CardService.newAction().setFunction('doIt'), CardService.ComposedEmailType.STANDALONE_DRAFT)
  .setOnClickAction(CardService.newAction().setFunction('notify')));

动作功能:

function doIt(event){
  validate the event['formInput'] object;
  if(valid the formInput)
    create  andr return the draft;
  else
    return null;
}

function notify(event){
  validate the event['formInput'] object;
  if(valid the formInput)
    return null;
  else
    return notify or rebuilded card with error info;
}

主要是简单的动作运行,而撰写什么也不做。如果我将Logger.log()函数放在回调函数中,api log 上只会出现一个。

任何人在验证和创建草稿之前尝试过吗?

4

1 回答 1

0

这个怎么样:

var action=CardService.newAction().setFunctionName('myFunction');
var validateCreateButton=CardService.newTextButton()
.setText('Validate & Create')
.setOnClickAction(action);
section.addWidget(validateCreateButton);


function myFunction(e) {
  doit(e);
  notify(e);
}
于 2019-12-26T17:35:07.253 回答