cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
Retrieve Values from a Modeless Dialog Box

Problem

Many applications require prompting the user for inputs or choices and then acting on that input. This recipe creates a modeless (i.e., non-modal) dialog box with choices. When the user clicks the Okay button to dismiss the window, it stores the user inputs into variables and then does whatever work is required. 

Solution

The New Window() function will create a window you can use to prompt the user for input. Inside the new window you can use input selector display boxes to collect the user choices.

 

You'll then use the Set Function or Set Script options on a Button Box to store the values from the display boxes into JSL variables.

 

The final part of the script in the Button Box does the work required after the user dismisses the window.

 

win = New Window( "Set the Value",
	H List Box( Text Box( "Set this value" ), num_edit_box1 = Number Edit Box( 42 ) ),
	check_box_1 = Check Box( "On" ),
	combo_box1 = Combo Box( {"Choice 1", "Choice 2", "Choice 3"} ),
	list_box1 = List Box( {"Choice 3", "Choice 4", "Choice 5"} ), 
	
	
	H List Box(
		Button Box( "OK", 
		
			//store results in jsl variables
			num_input = num_edit_box1 << get;
			check_box_input = check_box_1 << get;
			combo_box_input = combo_box1 << get selected;
			list_box_input = list_box1 << get selected;
	
			//close the window
			//wait until you've unloaded the input boxes before you closing
			//or else they'll be gone
			win << close window;
			
			//now do whatever work you want with the inputs
			Show( num_input, check_box_input, combo_box_input, list_box_input );
		),
		
		//a cancel button that closes the window and doesn't store store the results
		Button Box( "Cancel", win << close window )
	)
);

Discussion

Modeless dialogs are a bit trickier than modal dialogs since any code after the New Window() will be executed before the dialog is dismissed. That's why you have to put the "work" to be done in the button box script.

See Also

Retrieve values from a modeless dialog box

JSL Cookbook

If you’re looking for a code snippet or design pattern that performs a common task for your JSL project, the JSL Cookbook is for you.

This knowledge base contains building blocks of JSL code that you can use to reduce the amount of coding you have to do yourself.

It's also a great place to learn from the experts how to use JSL in new ways, with best practices.