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
samir
Level IV

How to force user to provide valid input

Hi ,

I am trying to force the user to give a valid entry: I display a modal window, and ask to give a value.

If this value is a string different than "" , then the code should go on using the value given. If not , the script should hang on or prompt the user to give correct input.

I tried using a modal window + hiding the OK button, but somehow, it does not do the job (see attached code).

Please help.

win = New Window( "Set a Value", 

	<<Modal,

	<<Return Result, 

	tb = Text Box( "Set this value" ), 

	variablebox = Text Edit Box( "", 
		//bb << enable(variablebox << get text !="");
		If( variablebox << get text != "",
			bb << Visibility( "Visible" )
		),

	), 

	bb = Button Box( "OK" ),
	bb << Visibility( "Hidden" ),
	If( variablebox << get text != "",
		bb << Visibility( "Visible" ),
		bb << Visibility( "Hidden" )
	), 

	//Button Box( "Cancel" ),
	
	

);
1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to force user to provide valid input

I prefer to explicitly use a Cancel button, but the design of your dialog is your business.

 

This modified version of the example I showed earlier should handle the case of the user clicking Cancel or the close window button.

 

Names Default to Here( 1 );

// put up dialog box for user entry
win = New Window( "Set a Value", 
	<<Modal,
	<<Return Result, 
	tb = Text Box( "Set this value" ), 
	variablebox = Text Edit Box( "",
		<< Set Function(
			Function( { me },
				content = me << Get Text;
				If( Is Missing( content ),
					bb << Enable( 0 ),
					bb << Enable( 1 )
				)
			)
		)
	), 
	bb = Button Box( "OK",
		<< Enable( 0 ),
		content = bb << Get Text;
	),
	Button Box( "Cancel" ),
);

// unload dialog
If( win["Button"] == -1, Throw( "User cancelled" ) );

// continue with remainder of script
Show( content );

View solution in original post

5 REPLIES 5

Re: How to force user to provide valid input

Try this approach:

 

Names Default to Here( 1 );

win = New Window( "Set a Value", 

	<<Modal,

	<<Return Result, 

	tb = Text Box( "Set this value" ), 

	variablebox = Text Edit Box( "",
		<< Set Function(
			Function( { me },
				content = me << Get Text;
				If( Is Missing( content ),
					bb << Enable( 0 ),
					bb << Enable( 1 )
				)
			)
		)
	), 

	bb = Button Box( "OK",
		<< Enable( 0 ),
		content = bb << Get Text;
	),
	Button Box( "Cancel" ),

);
samir
Level IV

Re: How to force user to provide valid input

Great !!!!

it does 99% of the job !

to be 100%, I need to do 2 modifications:

  1. comment out the code of the "cancel" button --> easy
  2. add something to exit the full code in case the user wants to cheat and clics on the "cross" symbol to close the modal window "win" without giving a string.
    Do you know how to do this ?

Re: How to force user to provide valid input

I prefer to explicitly use a Cancel button, but the design of your dialog is your business.

 

This modified version of the example I showed earlier should handle the case of the user clicking Cancel or the close window button.

 

Names Default to Here( 1 );

// put up dialog box for user entry
win = New Window( "Set a Value", 
	<<Modal,
	<<Return Result, 
	tb = Text Box( "Set this value" ), 
	variablebox = Text Edit Box( "",
		<< Set Function(
			Function( { me },
				content = me << Get Text;
				If( Is Missing( content ),
					bb << Enable( 0 ),
					bb << Enable( 1 )
				)
			)
		)
	), 
	bb = Button Box( "OK",
		<< Enable( 0 ),
		content = bb << Get Text;
	),
	Button Box( "Cancel" ),
);

// unload dialog
If( win["Button"] == -1, Throw( "User cancelled" ) );

// continue with remainder of script
Show( content );
samir
Level IV

Re: How to force user to provide valid input

Great !

it works perfectly.

Thans.

SDF1
Super User

Re: How to force user to provide valid input

Hi @samir,

 

  @Mark_Bailey has a really good starting point. I modified it slightly to what sounded like you were after -- the user entering a number.

Names Default To Here( 1 );
win = New Window( "Set a Value",
	<<Modal, 
	//<<Return Result,
	Text Box( "Set this value" ),
	variablebox = Number Edit Box(
		.,
		<<Set Function(
			Function( {my_value},
				content = my_value << Get;
				If( Is Missing( content ),
					bb << Enable( 0 ),
					bb << Enable( 1 )
				);
			)
	
		)
	),
	bb = Button Box( "OK",<< Enable( 0 ), content = bb << Get );
);
Print("Value is "|| Char(content) );

  You can also try the On Validate() option, but I think this returns a list of strings rather than a variable. In the above case, the new variable is "content", and could be passed to another function or JSL code that does something with it.

 

  Also note, if you invoke the variablebox as a Number Edit Box, JMP knows not to allow anything but numbers, positive or negative. So, if they enter anything but a number, then the window stays open. I don't think it can handle imaginary numbers without a special add-in.

 

Hope this helps!,

DS