0

I've got a Google script in Sheets which creates a sidebar. The sidebar is generated dynamically using the UiApp, rather than HTML. Users click on one of the radio buttons to make their selection (of which there can be over 200, and their values changing regularly, as they're taken from a particular sheet).

I'm trying to pass the value of the radio button through, but it's always coming up as undefined:

//get the values over
var MaxRow=250;
var LookIn=0;
var L1; var L2; var L3;
for(LookIn=1;LookIn<MaxRow;LookIn++)
{
  L1=sheet.getRange("AB" + LookIn);
  L2=sheet.getRange("AC" + LookIn);
  L3=sheet.getRange("AD" + LookIn);
  if(L1.getValues()!=""){UIInstance.add(UIInstance.createLabel("_")); UIInstance.add(UIInstance.createHTML("<b>" + L1.getValues() + "</b>"));}
  if(L2.getValues()!=""){UIInstance.add(UIInstance.createHTML("<b> > > " + L2.getValues() + "</b>"));}
  if(L3.getValues()!="")
  {
    var RadioHandler=UIInstance.createServerChangeHandler('radioButtonsChange');
    UIInstance.add(UIInstance.createRadioButton("MyButton").setId(L3.getValues).setText(L3.getValues()).addClickHandler(RadioHandler));
    UIInstance.add(UIInstance.createLabel(""));
  }
}
//add the sidebar
SpreadsheetApp.getUi()
    .showSidebar(UIInstance);
}

function radioButtonsChange(e)
{
  SpreadsheetApp.getUi().alert(e.parameter.source);
}

As we've got so many radio buttons, I'm basically using L3.getValues() to set their properties, then the handler to hopefully call it up. Currently it does call the handler which goes through to the radioButtonsChange, but it's always bringing up "undefined". I'm not convinced it's passing anything through.

1 Answers1

0

Okay, don't quite know what I did differently but it's working now.

First stuff:

var RadioHandler=UIInstance.createServerChangeHandler('radioButtonsChange');
  UIInstance.add(UIInstance.createRadioButton("MyButton").setId(L3.getValues()).setText(L3.getValues()).addClickHandler(RadioHandler));
  UIInstance.add(UIInstance.createLabel(""));

And the last bit:

function radioButtonsChange(e)
{
  SpreadsheetApp.getUi().alert(e.parameter.source);
}

Not a clue, go figure.