That article was somewhat helpful as is Example 2 for execDialog in the js_api_reference. I need to return the value of the radio button that was selected, and the examples either don't show how to do that or I'm not proficient enough at javascript to figure it out myself.
As near as I can tell, the answer lies somewhere in the dialog.store(). Radio buttons have a group_id. Ideally the group_id should be able to return the value of the button chosen, but I can't figure out how to do it and I can't find any detailed information of working with the Dialog object.
Below is my current code (annotated to show code I'm unsure of), refactored to use the commit handler and patterned after Example 2 for execDialog in the js_api_reference. Again, my goal is to return the value of whatever radio button was selected.
var oDlg =
{ strName: "", // a variable to hold our choice?
initialize: function(dialog) {
// set a default radio button, just as a test -- the default is the first radio button
dialog.load({"rd02": true});},
commit: function(dialog) {
var results = dialog.store(); // I'm not sure what dialog.store is supposed to do
// I tried putting a string in the parens, but it doesn't seem to do anything
// moreover, at the last line in this script I'm getting "ReferenceError: results is not defined"
// ideally, it would store the value of the radio group
this.strName = results["rado"];
app.alert(this.strName);
},
// I'm not convinced that this whole code block is necessary
getRadioSelection: function(results) {
for ( var i=1; i<=3; i++) {
if ( results["rd0"+i] ) {
switch
{
case 1:
var myResult = "complete";
break;
case 2:
var myResult = "needGuidance";
break;
case 3:
var myResult = "noActionNeeded";
}
}
};
return myResult;
}, // end of the code block that seems unnecessary
description:
{
name: "Save document to which folder?",
elements:
[
{
type: "cluster",
name: "Choose a folder",
elements:
[
{
type: "static_text",
name: "a static text string"
},
{
type: "radio",
item_id: "rd01",
group_id: "rado",
name: "completed folder",
value: "complete",
},
{
type: "radio",
item_id: "rd02",
group_id: "rado",
name: "need guidance",
value: "needGuidance",
},
{
type: "radio",
item_id: "rd03",
group_id: "rado",
name: "no action needed",
value: "noActionNeeded",
},
{
type: "ok_cancel",
},
]
},
]
}
};
var retn = app.execDialog(oDlg);
app.alert(retn,4);
app.alert(this.strName,4);
app.alert(results,4);
// I'm getting "ReferenceError: results is not defined"
The dialog box is rendering fine. I'm just trying to get the value of the radio button the user selected.
Christian
Here's a working version
var oDlg =
{ myFolder:"",
commit: function(dialog) { // this is a standard setup for a dialog object
var results = dialog.store(); // store the user's selection
// we have to examine each possiblity individually
if (results["rd01"]) {
this.myFolder = "complete";}
if (results["rd02"]) {
this.myFolder = "needGuidance";}
if (results["rd03"]) {
this.myFolder = "noActionNeeded";}
},
description:
{
name: "Save document to which folder?",
elements:
[
{
type: "cluster",
name: "Choose a folder",
elements:
[
/* I'm commenting this section out because it's not necessary for this particular
dialog box, but I don't want to forget that this static text area could be useful
{
type: "static_text",
name: "a static text string"
},*/
{
type: "radio",
item_id: "rd01",
group_id: "rado",
name: "completed folder",
value: "complete",
},
{
type: "radio",
item_id: "rd02",
group_id: "rado",
name: "need guidance",
value: "needGuidance",
},
{
type: "radio",
item_id: "rd03",
group_id: "rado",
name: "no action needed",
value: "noActionNeeded",
},
{
type: "ok_cancel",
},
]
},
]
}
};
if ('ok' == app.execDialog(oDlg))
app.alert("Radio button selected: " + this.oDlg.myFolder,4);