cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
orthogonal
Level II

How to check valid inputs in a Modal Dialog

I have written a jsl script which inputs three positive integers and creates a table.  It works fine if the user gives valid inputs.  My question is how can I verify the inputs to ensure that they are numeric and integers?  Additionally, I would like to have the checking done within the modal dialog so that it will check for invalid input and give the user an opportunity to correct it.  Lastly, my cancel button doesn't seem to abort the script.

Any help is appreciated.

//Create training, cross validation and test, column for a covariate input to DOE
New Window( "Create Cross Validation Covariate Table", 
	<<Modal,    
	Text Box( "Enter the number of runs for each set" ), 
	V List Box(
		Lineup Box( N Col( 2 ), 
			Text Box( "Training" ),
			ntrain_in = Number Edit Box( 100 ), 
			Text Box( "Cross Validation" ),
			ncv_in = Number Edit Box( 10 ), 
			Text Box( "Test" ),
			ntest_in = Number Edit Box( 10 ), 
		), 
	),    
	Button Box( "OK", 
        //What do I need to do to put the input checking here and only accept the 
		//input if valid?
		ntrain = ntrain_in << get;
		ncv = ncv_in << get;
		ntest = ntest_in << get;
	), 
	Button Box( "Cancel", 
		Throw( "Cancel Button Selected" )
        //this doesn't seem to work.  Any ideas?
	)
);
Show( ntrain, ncv, ntest );
//Need help on checking if valid input.
//each input should be a positive integer in the range [0,large integer]
If( Or( ntrain < 0, ntrain == "" ), 
	Show( ntrain );
    // how to check if numeric?
	ntrain = 0;    
	Throw( "ntrain value not valid" )
	;
);
M1 = J( 1, ntrain, 0 );
M2 = J( 1, ncv, 1 );
M3 = J( 1, ntest, 2 );
cv_dt = New Table( "Cross Validation for Covariate input to DOE", 
	New Column( "validation",
		Numeric,
		continuous, 
		Set Values( Concat( Concat( M1, M2, M3 ) ) )
	)
);

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User (Alumni) ms
Super User (Alumni)

Re: How to check valid inputs in a Modal Dialog

I think it would be better to do the checking before pressing "OK" (which typically closes a modal window... then it's late for regrets).

However, NumberEditBox() seems not to support scripts. Below is a variant of your example using NumberColEditBox() instead. Every edit activates a script that disables the OK button if one or more non-valid numbers are entered.

nw = New Window( "Create Cross Validation Covariate Table",
	<<Modal,
	Table Box(
		String Col Box( " ", {"Training", "Cross Validation", "Test"} ),
		nb = Number Col Edit Box(
			"Positive Integers only",
			[100, 10, 10],
			m = nb << get as matrix;
  // disable OK-button if non-valid number is entered
			bb << enable( 1 - Max( Is Missing( m ) | m < 0 | Floor( m ) != m ) );
		)
	),
	bb = Button Box( "OK", m = nb << get as matrix ),
	Button Box( "Cancel" )
);
If( Arg( nw[1] ) == -1,
	Stop()
); // Stop execution if "Cancel"
M1 = J( 1, m[1], 0 );
M2 = J( 1, m[2], 1 );
M3 = J( 1, m[3], 2 );
cv_dt = New Table( "Cross Validation for Covariate input to DOE",
	New Column( "validation", Numeric, continuous, Set Values( Concat( Concat( M1, M2, M3 ) ) ) )
);

 

View solution in original post

2 REPLIES 2
ms
Super User (Alumni) ms
Super User (Alumni)

Re: How to check valid inputs in a Modal Dialog

I think it would be better to do the checking before pressing "OK" (which typically closes a modal window... then it's late for regrets).

However, NumberEditBox() seems not to support scripts. Below is a variant of your example using NumberColEditBox() instead. Every edit activates a script that disables the OK button if one or more non-valid numbers are entered.

nw = New Window( "Create Cross Validation Covariate Table",
	<<Modal,
	Table Box(
		String Col Box( " ", {"Training", "Cross Validation", "Test"} ),
		nb = Number Col Edit Box(
			"Positive Integers only",
			[100, 10, 10],
			m = nb << get as matrix;
  // disable OK-button if non-valid number is entered
			bb << enable( 1 - Max( Is Missing( m ) | m < 0 | Floor( m ) != m ) );
		)
	),
	bb = Button Box( "OK", m = nb << get as matrix ),
	Button Box( "Cancel" )
);
If( Arg( nw[1] ) == -1,
	Stop()
); // Stop execution if "Cancel"
M1 = J( 1, m[1], 0 );
M2 = J( 1, m[2], 1 );
M3 = J( 1, m[3], 2 );
cv_dt = New Table( "Cross Validation for Covariate input to DOE",
	New Column( "validation", Numeric, continuous, Set Values( Concat( Concat( M1, M2, M3 ) ) ) )
);

 

orthogonal
Level II

Re: How to check valid inputs in a Modal Dialog

Thanks for the great example of how to code for input parameter checking.