cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
jthi
Super User

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);

 

 

-Jarmo
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Default button selection/highlight in modal window

Currently using the same workaround as mentioned on the opening message with fakebutton:

 

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);

Also something similar to this could most likely be used as a workaround Set focus on text edit box 

 

Also created new wish: Allow <<SetFocus to be used with interactive display elements (TextEditBox, Button...)  

-Jarmo

View solution in original post

4 REPLIES 4
ih
Super User (Alumni) ih
Super User (Alumni)

Re: Default button selection/highlight in modal window

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

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
jthi
Super User

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);
	);
);

 

-Jarmo
jthi
Super User

Re: Default button selection/highlight in modal window

Currently using the same workaround as mentioned on the opening message with fakebutton:

 

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);

Also something similar to this could most likely be used as a workaround Set focus on text edit box 

 

Also created new wish: Allow <<SetFocus to be used with interactive display elements (TextEditBox, Button...)  

-Jarmo