Our World Statistics Day conversations have been a great reminder of how much statistics can inform our lives. Do you have an example of how statistics has made a difference in your life? Share your story with the Community!
Choose Language Hide Translation Bar
Highlighted
jthi
Level II

Default button selection/highlight in modal window

Is it possible to set specific button as selected button in modal window to allow usage of that button with enter/space press?

 

In the example script I have added I would like to have default selection to be "OK" button of modal window but by default it is set as first selection of radio box (in this case "Option 1") and I haven't figured out how to change it. I managed to do this by creating fake button as first element in the new window (selected by default) which clicks the Ok button but I feel this is a bit hacky way to get it working (commented out in the example script).

 

Names Default To Here(1);

okPushed = 0;
nw = New Window("Modal window", << modal, Show toolbars(0), Show menu(0),
	//fakebutton = Button Box("     ",<< Style("underline"), << set function(ok_button << click)),
	rb = Radio Box(
		{"Option 1", "Option 2"}, << Set(2)	
	),
	Panelbox("Actions",
		Hlistbox(
			ok_button = button box("OK", okPushed = 1; sel = rb << get selected),
			cancel_button = button box("Cancel", okPushed = 0; stop();),
		)
	),
);

if(okPushed == 0, stop());
show(sel);

 

 

3 REPLIES 3
Highlighted
ih
ih
Level VII

Re: Default button selection/highlight in modal window

Can you put the OK button at the top of the window? 

Highlighted
txnelson
Super User

Re: Default button selection/highlight in modal window

yes...here is an example

 

Names Default To Here( 1 );

nw = New Window("At the Top", << modal,
	v list box(
		button box("OK", nw << close window ),
		spacer box(size(0,25)),
		text box(" at the bottom")
	)
)

 

Jim
Highlighted
jthi
Level II

Re: Default button selection/highlight in modal window

Moving the buttons to top could be one option to avoid adding empty button to the top.

 

Quickly testing it seems that if I don't make the New window modal, enter key press will press OK button instead of the first option of radio buttons.

 

Names Default To Here(1);

okPushed = 0;
nw = New Window("Modal window", Show toolbars(0), Show menu(0),
	rb = Radio Box(
		{"Option 1", "Option 2"}, << Set(2)	
	),
	Panelbox("Actions",
		Hlistbox(
			ok_button = button box("OK", okPushed = 1; sel = rb << get selected; nw << close window;),
			cancel_button = button box("Cancel", okPushed = 0; nw << close window;)
		)
	),
);
nw << on close(
	if(okPushed == 0, show(sel, okPushed); stop(),
		show(sel, okPushed);
	);
);

 

Article Labels