'Set dropdown select by value
Is it possible to set selected specific item of dropdown in Google apps script (Gmail add-on) from the action?
Example: I have one dropdown with 5 items (10, 20, 30, 40, 50) and one button. Default selected item of dropdown is 10 (dropdown.AddItem(10, 10, true)). When I click button I want to change selected item of dropdown to 40. Is it possible to do?
UPDATED:
function onHomepage(e) {
var max = CardService.newSelectionInput()
.setType(CardService.SelectionInputType.DROPDOWN)
.setTitle('Max')
.setFieldName('max_field')
.setOnChangeAction(CardService.newAction()
.setFunctionName('maxHandler'));
for (let i = 10; i <= 100; i += 10) {
var selected = false;
if (i === 10)
selected = true;
max.addItem(i + "$", i, selected);
}
var _btn = CardService.newTextButton()
.setText('Button')
.setTextButtonStyle(CardService.TextButtonStyle.FILLED)
.setOnClickAction(CardService.newAction()
.setFunctionName('btnClicked'));
var btn = CardService.newButtonSet()
.addButton(_btn);
var section = CardService.newCardSection()
.addWidget(max)
.addWidget(btn);
return CardService.newCardBuilder()
.setName('cardName')
.addSection(section)
.build();
}
function btnClicked(e) {
var selectedMax = e.formInput.max_field;
console.log(selectedMax);
// TODO: set selected dropdown for 40$ item
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

