Reply To: How to make a click radiobutton eventListener work?

#14323364
Jeremy Howard
Participant

Hey there,

I am back at my computer and I threw this script together as an example to show you how the “onClick” function can be used to accomplish what you are trying to accomplish.

Check this script out and let me know if you have any questions!

//————— BEGIN SCRIPT —————//

#targetengine ‘my_session’

var myDialog = new Window (‘palette’, “Show UI Elements With Radio Button Click”, undefined, {minimizeButton: true, independent: false, closeButton: true, borderless: true, name: “Data Query Panel”});
myDialog.preferredSize.width = 500;
myDialog.preferredSize.height = 100;
myDialog.alignChildren = [‘top’, ‘left’];
myDialog.margins[1] = 10;
myDialog.spacing = 10;

//– Group for radio buttons –//
var radioButtonsGroup = myDialog.add(‘group {orientation: “column”, alignChildren: “left”, alignment: “left”}’)
var radio1 = radioButtonsGroup.add(‘radiobutton’, undefined, “Radio Button One”);
radio1.value = false;
var radio2 = radioButtonsGroup.add(‘radiobutton’, undefined, “Radio Button Two”);
radio2.value = false;
var radio3 = radioButtonsGroup.add(‘radiobutton’, undefined, “This Radio Button Shows More Stuff.”);
radio3.value = false;
//– End group for radio buttons –//

//– Everything within the “hiddenTextGroup” will be hidden when the panel is first drawn –//
var hiddenTextGroup = myDialog.add(‘group {orientation: “column”, alignChildren: “left”, alignment: “left”}’)
hiddenTextGroup.size = [0,0];
hiddenTextGroup.hide();

var revealedText = hiddenTextGroup.add(‘statictext’, undefined, “Some static text”);
revealedText.preferredSize.width = 500;

var myEditText = hiddenTextGroup.add(‘edittext’, undefined, undefined);
myEditText.preferredSize.width = 500;
//– End of “hiddenTextGroup” –//

//– A group for my buttons in the panel –//
var buttonGroup = myDialog.add(‘group’);
buttonGroup.alignment = [‘right’,’bottom’];
buttonGroup.margins[1] = 15;

//– My Buttons
var cancelButton = buttonGroup.add(‘button’, undefined, “Close Panel”,{name: “Close Panel”});
var proceedButton = buttonGroup.add(‘button’, undefined, “Submit This Stuff”,{name: “proceedButton”});

//– Event listener – activated with the radio button is clicked. –//
radio3.onClick = function(){
hiddenTextGroup.size = [500,100];
hiddenTextGroup.show();
myDialog.layout.layout (true);
}

proceedButton.onClick = function() {
alert(“You clicked Proceed.”);
myDialog.close(1); //–close the dialog, return 1
}

cancelButton.onClick = function() {
myDialog.close(2); //–close the dialog, return 2
}

var dialogResult = myDialog.show();

if(dialogResult == 1){
//– Do some stuff because the proceed button was clicked
}else if (dialogResult== 2){
exit(0);
}

//————— END SCRIPT —————//

This article was last modified on December 29, 2019

Comments (0)

Loading comments...