How to get the selected value of a selectbox and pass it to an action?

和自甴很熟 提交于 2019-12-02 06:52:47

问题


I need to pass the value of the selectbox to it's widget's handler function

var payment = CardService.newSelectionInput()
  .setType(CardService.SelectionInputType.DROPDOWN)
  .setTitle("payment mode")
  .setFieldName("payment_mode")
  .addItem("Debit card", "contact", false)
  .addItem("Net banking", "lead", true)
  .setOnChangeAction(CardService.newAction().setFunctionName("onModeChange"));
section.addWidget(payment);

I expect something like setFunctionName("onModeChange").setParams(payment.value)


回答1:


I think that your script is almost the correct. You can achieve what you want by modifying a little. In your case, you want to retrieve contact or lead at the function onModeChange. If my understanding is correct, how about this modification?

In your script, you can retrieve the selected values as follows. When an user selects, the selected values are sent to onModeChange, immediately. Please add this function in your script.

function onModeChange(e) {
    console.log(e.formInput.payment_mode)
}

If the user selects Debit card and Net banking, you can retrieve contact and lead at e.formInput.payment_mode, respectively.

If you want to give the additional values when the user selects, please modify

From
.setOnChangeAction(CardService.newAction().setFunctionName("onModeChange"))
To :
.setOnChangeAction(CardService.newAction().setFunctionName("onModeChange").setParameters({key1: "value1"}))

By this modification, at onModeChange(e), you can retrieve the added values by e.parameters.key1.

Note :

  • This sample supposes that both your script works and you can see the select box at the gmail addon. If your script didn't work yet, please tell me.

References :

  • setFunctionName()
  • setParameters()

If I misunderstand your question, I'm sorry.



来源:https://stackoverflow.com/questions/50444238/how-to-get-the-selected-value-of-a-selectbox-and-pass-it-to-an-action

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