Modal Window Cancel buttonI have created a script that begins with a modal window that lets the user select one or more check boxes in a list. The script works perfectly fine, the only problem is that the modal window has the "OK" button and no "Cancel" button. If the user exits the modal window using the X in the top corner, the first part of the script (that doesn't require any of the information from the check box list) still runs. How can I get this script to only run if the user clicks "OK"? The modal window script is below (sorry I know its very long):
Names Default To Here( 1 );
Win1 = New Window( "Base Count Selection",
<<MODAL></MODAL>
Re: Modal Window Cancel buttonThe OK button is automatically generated for all Modal windows, although you can create your own OK and Cancel buttons.
I typically separate my code into functions (although you can also use expressions) and then call those functions from the OK button and do not do anything in the Cancel button, causing the script to stop.
Here is an example of using this methodology with an Expression:
doSomething = Expr(
Print( "Do something" )
);
New Window( "Test",
<<MODAL></MODAL>
Alternatively, you can use the return value from the New Window to determine if you script should continue. The value will be {Button( 1 )} if OK was clicked or will be {Button( -1 )} if the Cancel button or X was clicked.
nw = New Window( "Test",
<<MODAL></MODAL>
Re: Modal Window Cancel buttonYou can add in a cancel button to a modal window along with an OK button and the window will return a "1" for OK and a "-1" for Cancel
H List Box(button box("Cancel"),button box("OK"))