cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
aallman
Level III

Modal Window Cancel button

I 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, 
	
	V List Box(
		Spacer Box( size( 20, 20 ) ),
		Text Box( "Select which bases to create count columns for.", <<Set Font Size( 10 ), <<Margin( 10, 10 ) ), 
		
		Text Box(
			"The 'Select All' check boxes will create individual count columns for each of the bases of that type. The 'Total Count' option will create a separate column containing the total modified base count for each base type that is selected.
Note that thioates are counted as part of the base to the left. For example, in the sequence AGTGT*C the thioate is counted as a thioated T.",
			<<Margin( 25, 0 ),
			<<Set Width( 1220 )
		),
		Spacer Box( size( 20, 20 ) ),
		h = H List Box(
			Border Box( Left( 15 ), Right( 15 ), top( 15 ), bottom( 27 ), sides( 15 ),
				V List Box(
					Text Box( "Modified Bases", <<Set Font Size( 11 ) ),
					Spacer Box( size( 10, 10 ) ),
					Lineup Box( N Col( 5 ), spacing( 15, 1 ), 
					
						Text Box( "LNA Bases", <<Set Font Size( 10 ) ),
						Text Box( "OMe Bases", <<Set Font Size( 10 ) ),
						Text Box( "MOE Bases", <<Set Font Size( 10 ) ),
						Text Box( "cEt BNA Bases", <<Set Font Size( 10 ) ),
						Text Box( "Fluoro Bases", <<Set Font Size( 10 ) ), 
						
						Spacer Box( size( 10, 5 ) ),
						Spacer Box( size( 10, 5 ) ),
						Spacer Box( size( 10, 5 ) ),
						Spacer Box( size( 10, 5 ) ),
						Spacer Box( size( 10, 5 ) ), 
						
						lnacb = Check Box( {"+A", "+C", "+T", "+G"} ),
						omecb = Check Box( {"mA", "mC", "mT", "mG"} ),
						moecb = Check Box( {"MOErA", "MOErC", "MOErT", "MOErG", "MOErU"} ),
						bnacb = Check Box( {"cEt A", "cEt C", "cEt T", "cEt G"} ),
						flucb = Check Box( {"FA", "FC", "FU", "FG"} ), 		
						
						Spacer Box( size( 10, 10 ) ),
						Spacer Box( size( 10, 10 ) ),
						Spacer Box( size( 10, 10 ) ),
						Spacer Box( size( 10, 10 ) ),
						Spacer Box( size( 10, 10 ) ), 	
					
						lnaa = Check Box( "Select All", <<SetFunction( lnacb << Set All( (lnaa << Get), run script( 1 ) ) ) ),
						omea = Check Box( "Select All", <<SetFunction( omecb << Set All( (omea << Get), run script( 1 ) ) ) ),
						moea = Check Box( "Select All", <<SetFunction( moecb << Set All( (moea << Get), run script( 1 ) ) ) ),
						bnaa = Check Box( "Select All", <<SetFunction( bnacb << Set All( (bnaa << Get), run script( 1 ) ) ) ),
						flua = Check Box( "Select All", <<SetFunction( flucb << Set All( (flua << Get), run script( 1 ) ) ) ), 
							
						lnat = Check Box( "Total LNA Count" ),
						omet = Check Box( "Total OMe Count" ),
						moet = Check Box( "Total MOE Count" ),
						bnat = Check Box( "Total cEt Count" ),
						flut = Check Box( "Total Fluoro Count" )
					)
				), 
				
				<<Margin( Right( 10 ) )
			), 
			
		
			b = Border Box( Left( 15 ), Right( 12 ), top( 15 ), bottom( 15 ), sides( 15 ),
				V List Box(
					H List Box(
						Text Box( "Thioated Bases", <<Set Font Size( 11 ) ),
						Spacer Box( size( 50, 10 ) ),
						(all = Check Box( "Count All Thioates in Sequence" ))
					),
					Spacer Box( size( 10, 10 ) ),
					Lineup Box( N Col( 5 ), spacing( 15, 1 ), 
						
						Text Box( "Thioated DNA", <<Set Font Size( 10 ) ),
						Text Box( "Thioated LNA", <<Set Font Size( 10 ) ),
						Text Box( "Thioated OMe", <<Set Font Size( 10 ) ),
						Text Box( "Thioated MOE", <<Set Font Size( 10 ) ),
						Text Box( "Thioated cEt", <<Set Font Size( 10 ) ), 
						
						Spacer Box( size( 10, 5 ) ),
						Spacer Box( size( 10, 5 ) ),
						Spacer Box( size( 10, 5 ) ),
						Spacer Box( size( 10, 5 ) ),
						Spacer Box( size( 10, 5 ) ), 
						
						thicb = Check Box( {"A*", "C*", "T*", "G*"} ),
						lthicb = Check Box( {"+A*", "+C*", "+T*", "+G*"} ),
						omethicb = Check Box( {"mA*", "mC*", "mT*", "mG*"} ),
						moethicb = Check Box( {"MOErA*", "MOErC*", "MOErT*", "MOErG*"} ),
						bthicb = Check Box( {"cEt A*", "cEt C*", "cEt T*", "cEt G*"} ), 
							
						Spacer Box( size( 9, 25 ) ),
						Spacer Box( size( 9, 23 ) ),
						Spacer Box( size( 9, 22 ) ),
						Spacer Box( size( 9, 22 ) ),
						Spacer Box( size( 9, 22 ) ), 
							
						thia = Check Box( "Select All", <<SetFunction( thicb << Set All( (thia << Get), run script( 1 ) ) ) ),
						lthia = Check Box( "Select All", <<SetFunction( lthicb << Set All( (lthia << get), run script( 1 ) ) ) ),
						omethia = Check Box( "Select All", <<SetFunction( omethicb << Set All( (omethia << Get), run script( 1 ) ) ) ),
						moethia = Check Box( "Select All", <<SetFunction( moethicb << Set All( (moethia << Get), run script( 1 ) ) ) ),
						bthia = Check Box( "Select All", <<SetFunction( bthicb << Set All( (bthia << Get), run script( 1 ) ) ) ), 
						
						H List Box( thit = Check Box( "" ), Text Box( "Total Thioated DNA Count", <<Set Width( 100 ), <<Set Wrap( 100 ) ) ),
						H List Box( lthit = Check Box( "" ), Text Box( "Total Thioated LNA Count", <<Set Width( 100 ), <<Set Wrap( 100 ) ) ),
						H List Box( omethit = Check Box( "" ), Text Box( "Total Thioated OMe Count", <<Set Width( 100 ), <<Set Wrap( 100 ) ) ),
						H List Box( moethit = Check Box( "" ), Text Box( "Total Thioated MOE Count", <<Set Width( 100 ), <<Set Wrap( 100 ) ) ),
						H List Box( bthit = Check Box( "" ), Text Box( "Total Thioated cEt Count", <<Set Width( 80 ), <<Set Wrap( 80 ) ) ), 

					)
				)
			)
		),
		Spacer Box( size( 25, 60 ) ), 
				
	)
);
2 REPLIES 2
txnelson
Super User

Re: Modal Window Cancel button

You 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"))
Jim

Re: Modal Window Cancel button

The 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,
	Text Box( "Press OK to do something." ),
	H List Box(
		Button Box( "OK", doSomething ),
		Button Box( "Cancel" )
	)
);

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,
	Text Box( "Press OK to do something." ),
	H List Box(
		Button Box( "OK" ),
		Button Box( "Cancel" )
	)
);

// If cancel or X was clicked, stop the script
If( nw == {Button( -1 )}, Stop() );

Print( "Do something" );
Justin