For the latest version of JMP Help, visit JMP.com/help.


Scripting Guide > Display Trees > Modal Windows > Construct a Modal Window
Publication date: 04/30/2021

Construct a Modal Window

When you submit a script with a modal window, JMP draws the window, waits for the user to make choices and click OK, and then stores a list of the variables with their values. Any attempt to click outside the window produces an error sound, and script execution is suspended until the user clicks OK or Cancel.

The Column Dialog() function is specifically intended to prompt users to choose columns from the current (topmost) data table. Windows created by Column Dialog() are also modal windows.

Tips:

Put all the modal windows near the beginning of the script, if possible. This way, all the user interaction can be accomplished at once, and then users can leave JMP to finish its work unattended.

Make sure your modal windows give the user enough information. Do not just present a number field. Tell users how the number is used. If there are limits for valid responses, say so.

A very simple modal window might request a value for one variable:

win = New Window( "Set a Value",
	<<Modal,
	Text Box( "Set this value" ),
	variablebox = Number Edit Box( 42 ),
	Button Box( "OK" ),
	Button Box( "Cancel" )
);

Notice that the argument to Number Edit Box() is the default value, 42.

Figure 11.35 Sample Modal Display Box 

If you click OK, the window closes and {Button(1)} is returned. To get the value entered in the box, use the Return Result message and a subscript into the window. Note that the deprecated Dialog() returns the list of variable assignments the same way.

win = New Window( "Set a Value",
	<<Modal,
	<<Return Result,
	Text Box( "Set this value" ),
	variablebox = Number Edit Box( 42 ),
	Button Box( "OK" ),
	Button Box( "Cancel" )
);
 

// create a subscript to the variablebox variable

Write( win["variablebox"] );

In this example, the user typed 33 in the number edit box. That value is stored in win.

If you click Cancel, the window closes, it returns {Button(-1)}, and the script continues.

To detect whether the user clicked Cancel, add the following expression:

If( win["Button"] == 1,
	Print( win["variablebox"] );
	,
	Print("Canceled")
);

Note that a modal window must have at least one button. If you omit the Button Box() from your script, an OK button is automatically included. To omit the OK button, set the visibility to collapse.

win = New Window( "No OK Button",
	<<Modal,
	b = Button Box( "Close Window", b << Close Window ),
	bb = Button Box( "OK", <<Visibility( "collapse" ) )
);

Note: Modal windows require at least one button for dismissing the window. You can use OK, Yes, No, or Cancel to label modal window buttons. If you do not include at least one of these buttons in a modal window, JMP adds an OK button.

Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).