Gmail add ons using radio button

225 views
Skip to first unread message

Mohit Baghel

unread,
Mar 5, 2022, 8:33:20 AM3/5/22
to Google Apps Script Community
Hi, 
I want to use radio button in my card view for creating a form like structure in my gmail addon, how to get value of the selected radio button from user
Eg. 
option1
option2
option3

now how to know which options has been selected by user (I have not used HTML , I have implemented using cardservice)

Clark Lind

unread,
Mar 6, 2022, 12:19:29 PM3/6/22
to Google Apps Script Community
After you add the radio buttons and other form elements, you will likely have a button at the end that will take some action based on a different function you will use to handle the action. When that happens, the click event passes all the card info to the function where you can get the information.

Here is a simple example for Gmail:

function onGmailMessage(e) {
//build some card elements
        var cardSection = CardService.newCardSection()
//add radio buttons
        .addWidget(CardService.newSelectionInput()
            .setFieldName('select1') //this is the "key"
            .setTitle('Select your option below:')
            .setType(CardService.SelectionInputType.RADIO_BUTTON)
            .addItem('Option1', 'option1', false) //these are the "values"
            .addItem('Option2', 'option2', false) //these are the "values"
            .addItem('Option3', 'option3', false)) //these are the "values"
//add a button to take some action
        .addWidget(CardService.newButtonSet()
            .addButton(CardService.newTextButton()
                .setText('Submit')
                .setTextButtonStyle(CardService.TextButtonStyle.FILLED)
                .setDisabled(false)
                .setOnClickAction(CardService.newAction()
                    .setFunctionName("radioBtnTest")))); //the function that will be called when the button is pressed

//create the actual card
    var card = CardService.newCardBuilder()
        .setName("HomePage")
        .addSection(cardSection)
        .build();
    return card;
}

//the function the handle the card data
function radioBtnTest(e) {      //pass in the card event data
  console.log(e.formInput.select1);
  console.log(e);  //to see the whole event object
Reply all
Reply to author
Forward
0 new messages