<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to check valid inputs in a Modal Dialog in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-check-valid-inputs-in-a-Modal-Dialog/m-p/9614#M9427</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the great example of how to code for input parameter checking.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 26 Sep 2014 09:56:19 GMT</pubDate>
    <dc:creator>orthogonal</dc:creator>
    <dc:date>2014-09-26T09:56:19Z</dc:date>
    <item>
      <title>How to check valid inputs in a Modal Dialog</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-check-valid-inputs-in-a-Modal-Dialog/m-p/9612#M9425</link>
      <description>&lt;P&gt;I have written a jsl script which inputs three positive integers and creates a table.&amp;nbsp; It works fine if the user gives valid inputs.&amp;nbsp; My question is how can I verify the inputs to ensure that they are numeric and integers?&amp;nbsp; 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.&amp;nbsp; Lastly, my cancel button doesn't seem to abort the script.&lt;/P&gt;
&lt;P&gt;Any help is appreciated.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;//Create training, cross validation and test, column for a covariate input to DOE
New Window( "Create Cross Validation Covariate Table", 
	&amp;lt;&amp;lt;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 &amp;lt;&amp;lt; get;
		ncv = ncv_in &amp;lt;&amp;lt; get;
		ntest = ntest_in &amp;lt;&amp;lt; 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 &amp;lt; 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 ) ) )
	)
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 17:51:51 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-check-valid-inputs-in-a-Modal-Dialog/m-p/9612#M9425</guid>
      <dc:creator>orthogonal</dc:creator>
      <dc:date>2018-07-23T17:51:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to check valid inputs in a Modal Dialog</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-check-valid-inputs-in-a-Modal-Dialog/m-p/9613#M9426</link>
      <description>&lt;P&gt;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).&lt;/P&gt;
&lt;P&gt;However, &lt;EM&gt;NumberEditBox()&lt;/EM&gt; seems not to support scripts. Below is a variant of your example using &lt;EM&gt;NumberColEditBox()&lt;/EM&gt; instead. Every edit activates a script that disables the OK button if one or more non-valid numbers are entered.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;nw = New Window( "Create Cross Validation Covariate Table",
	&amp;lt;&amp;lt;Modal,
	Table Box(
		String Col Box( " ", {"Training", "Cross Validation", "Test"} ),
		nb = Number Col Edit Box(
			"Positive Integers only",
			[100, 10, 10],
			m = nb &amp;lt;&amp;lt; get as matrix;
  // disable OK-button if non-valid number is entered
			bb &amp;lt;&amp;lt; enable( 1 - Max( Is Missing( m ) | m &amp;lt; 0 | Floor( m ) != m ) );
		)
	),
	bb = Button Box( "OK", m = nb &amp;lt;&amp;lt; 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 ) ) ) )
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 17:47:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-check-valid-inputs-in-a-Modal-Dialog/m-p/9613#M9426</guid>
      <dc:creator>ms</dc:creator>
      <dc:date>2018-07-23T17:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to check valid inputs in a Modal Dialog</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-check-valid-inputs-in-a-Modal-Dialog/m-p/9614#M9427</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the great example of how to code for input parameter checking.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Sep 2014 09:56:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-check-valid-inputs-in-a-Modal-Dialog/m-p/9614#M9427</guid>
      <dc:creator>orthogonal</dc:creator>
      <dc:date>2014-09-26T09:56:19Z</dc:date>
    </item>
  </channel>
</rss>

