Google Sheets script - get value from radio button, currently undefined

回眸只為那壹抹淺笑 提交于 2019-12-11 19:34:36

问题


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:


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.



来源:https://stackoverflow.com/questions/31672545/google-sheets-script-get-value-from-radio-button-currently-undefined

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