Is it possible to design a modal window with multiple "OK" choices? I think my main difficulty is closing the window after selection of the second OK button. Is there a more clever way to do this? I am using JMP11. Example is below.
Thanks!
w1 = New Window( "New Window",
<<Modal,
// Get user input,
H List Box(
Button Box( "OK",
// Proceed with option 1
),
Button Box( "Other OK",
w1 << Close Window; // I can not get this to work.
// Proceed with option 2
),
Button Box( "Cancel", Throw( "Script cancelled by user." ) )
)
);
It looks like Eric's solution works in (soon-to-be-released) JMP 12, but JMP 11 has a different behavior.
One problem in the original script is that w1 cannot be used until the New Window call completes, and in the case of a Modal window the call does not complete until the window is dismissed! And because the window is gone by the time the call returns, the return value from a Modal call to New Window is not a window reference at all. Instead it is {Button(1)} if OK was pressed and {Button(-1)} if Cancel was pressed.
Fortunately, you can send a <<Close Window message to any display box. The following script should work in either JMP 11 or JMP 12:
w1 = New Window( "New Window",
<<Modal,
// Get user input,
H List Box(
Button Box( "OK",
// Proceed with option 1
),
b = Button Box( "Other OK",
b << Close Window;
// Proceed with option 2
),
Button Box( "Cancel", Throw( "Script cancelled by user." ) )
)
);
Note that the behavior for the added button is closer to 'Cancel' than 'OK' - the return value w1 will be {Button(-1)} for the "Other OK" button and the On Validate() script [if it exists] will not be run. That's ok - you can simply do your own validation within the button script, but keep this in mind if looking at the return value from New Window().
Try Current Window() instead of trying to refer to w1. This worked for me:
w1 = New Window( "New Window",
<<Modal,
// Get user input,
H List Box(
Button Box( "OK",
// Proceed with option 1
),
Button Box( "Other OK",
// w1 << Close Window; // I can not get this to work.
Current Window() << Close Window;
Write( "\!NHello from other OK button" );
// Proceed with option 2
),
Button Box( "Cancel", Throw( "Script cancelled by user." ) )
);
Hi Eric,
Thank you for the response. When I run your script,
Current Window() << Close Window;
closes the Script window, not the message box. Are you doing anything special to make it work?
It looks like Eric's solution works in (soon-to-be-released) JMP 12, but JMP 11 has a different behavior.
One problem in the original script is that w1 cannot be used until the New Window call completes, and in the case of a Modal window the call does not complete until the window is dismissed! And because the window is gone by the time the call returns, the return value from a Modal call to New Window is not a window reference at all. Instead it is {Button(1)} if OK was pressed and {Button(-1)} if Cancel was pressed.
Fortunately, you can send a <<Close Window message to any display box. The following script should work in either JMP 11 or JMP 12:
w1 = New Window( "New Window",
<<Modal,
// Get user input,
H List Box(
Button Box( "OK",
// Proceed with option 1
),
b = Button Box( "Other OK",
b << Close Window;
// Proceed with option 2
),
Button Box( "Cancel", Throw( "Script cancelled by user." ) )
)
);
Note that the behavior for the added button is closer to 'Cancel' than 'OK' - the return value w1 will be {Button(-1)} for the "Other OK" button and the On Validate() script [if it exists] will not be run. That's ok - you can simply do your own validation within the button script, but keep this in mind if looking at the return value from New Window().
Thanks Dan!
Hey guys,
Another wrinkle to this question: is there a way to have a modal dialog box without the OK or Cancel buttons?
nw = new window("Test Modal", << modal(),
panelbox("Actions",
hlistbox(
a = button box("Close A",
print("Closing with A");
a << close window;
),
b = button box("Close B",
print("Closing with B");
b << close window;
)
)
)
);
I'd also like this. The OK-ness of a button should be related to a property of the button other than the button title.
No, there is currently no way to avoid the addition of the OK button in this case. This is done to guarantee that the window can be dismissed.
Maybe just a curiosity, but it is possible to have two working "OK" buttons as long as one is a "YES" button.
In the modal window generatet by the code below, pressing the first "OK" or the "YES" both return {Button( 1 )} whereas the second "OK" is inactive.
New Window( "New Window",
<<Modal,
H List Box(
Button Box( "OK" ), // Works!
Button Box( "OK" ), // Useless!
Button Box( "YES" ), // Works!
)
);
MS, thanks for pointing this out. We do look for different names for the buttons. Generally this is just to handle the OK/Cancel and Yes/No variants, but yes, they can be used at the same time.