How to find out which radio camera is selected?

I have 3 radio buttons in my Ui in the same radio group. They are,

var rbutton1 = app.createRadioButton('dist','5 miles');

var rbutton2 = app.createRadioButton('dist','10 miles');

var rbutton3 = app.createRadioButton('dist','25 miles');

In the event handler function, the variable e.parameter.dist gives true or false only based on whether rbutton3 (the last switch) is set or not. Is there a way to determine which radio button is selected exactly?

+5
source share
4 answers

The only way the group of radio buttons works (as provided by the design) is to use them in FormPaneland see the name (in your case "dist") on doPost from the form submit action.

, , , . , . , , .

+2

:

eventData.parameter.source

, addClickHandler.

-

0

, . , . Serge answer .

0

, , listBox, .

: ( )

function radiotest() {
  var app = UiApp.createApplication();
  var panel = app.createVerticalPanel();
  var radioValue = app.createTextBox().setId('radioValue');
      radioValue.setId("radioValue").setName("radioValue");
  var listhandler = app.createServerHandler('listhandler').addCallbackElement(panel); 
  var list = app.createListBox().addChangeHandler(listhandler).setName('list');    
  for(var i = 1; i < 10; i++){
    var name = 'choice '+i;
    list.addItem('Activate '+name,name)
    var handler = app.createClientHandler().forTargets(radioValue).setText(name);
    panel.add(app.createRadioButton('radioButtonGroup',name).addValueChangeHandler(handler).setId(name));
  }
  panel.add(radioValue);
  var getit=app.createButton("Valide").setId("val");
  panel.add(getit).add(list)                   
  var handler = app.createServerHandler("valide")
  handler.addCallbackElement(panel)
  getit.addClickHandler(handler);
  app.add(panel);
SpreadsheetApp.getActiveSpreadsheet().show(app);// show app 
}
//
function valide(e){ ;// This function is called when key "validate" is pressed 
  var sh = SpreadsheetApp.getActiveSheet();
  var RadioButton = e.parameter.radioValue;               
  sh.getRange('A1').setValue(RadioButton);
  var app = UiApp.getActiveApplication();
  return app;
}​

function listhandler(e){ ;// This function is called when listBox is changed
  var sh = SpreadsheetApp.getActiveSheet();
  var app = UiApp.getActiveApplication();
  var listvalue = e.parameter.list
  var radioValue = app.getElementById('radioValue').setValue(listvalue)
  sh.getRange('A2').setValue(listvalue);
  var radiobutton = app.getElementById(listvalue)
  radiobutton.setValue(true)
return app;
}​

radioButton textBox, listBox , ... :

enter image description here

, eddyparkinson, e.parameter.source, radioButton "". () .

function radiotest2() {
  var app = UiApp.createApplication();
  var panel = app.createVerticalPanel();
  var listhandler = app.createServerHandler('listhandler2').addCallbackElement(panel); 
  var list = app.createListBox().addChangeHandler(listhandler).setName('list');    
  var handler = app.createServerHandler("valide2")
  handler.addCallbackElement(panel)
  for(var i = 1; i < 10; i++){
    var name = 'choice '+i;
    list.addItem('Activate '+name,name)
    panel.add(app.createRadioButton('radioButtonGroup',name).setId(name).addClickHandler(handler));
  }
  panel.add(list)                   
  app.add(panel);
SpreadsheetApp.getActiveSpreadsheet().show(app);// show app 
}


function valide2(e){ ;// This function is called when a radioButton is selected
  var sh = SpreadsheetApp.getActiveSheet();
  var source = e.parameter.source;
  var radioValue = '';
  if(source.match('choice')=='choice'){radioValue=source}
  sh.getRange('A1').setValue(radioValue);
  var app = UiApp.getActiveApplication();
  return app;
}​

function listhandler2(e){ ;// This function is called when listBox is changed
  var sh = SpreadsheetApp.getActiveSheet();
  var app = UiApp.getActiveApplication();
  var listvalue = e.parameter.list
  sh.getRange('A2').setValue(listvalue);
  var radiobutton = app.getElementById(listvalue)
  radiobutton.setValue(true)
return app;
}​
0

All Articles