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
PunitPanjwani
Level II

How to limit the user entry to 7 digits in NumberEditBox?

ECN = 0,

Text Box( "System ECN:" ),

S1 = Number Edit Box(ECN, <<Set Property( "MaxLength", 7)),

The user shouldn't be able to enter more than 7 digits. For example: 1234567... the user shouldn't be able to enter 8.

 

How did achieve this?

 

Any help is appreciated.

 

2 ACCEPTED SOLUTIONS

Accepted Solutions

Re: How to limit the user entry to 7 digits in NumberEditBox?

This version requires the user to commit the changes to the number.

Names Default to Here( 1 );

last = eon = 0;

New Window( "Only Seven",
	Outline Box( "Enter EON",
		Line Up Box( N Col( 2 ),
			Text Box( "System EON:" ),
			neb = Number Edit Box( eon,
				<< Set Integer Only( 1 ),
				<< Set Minimum( 0 ),
				<< Set Tip( "Enter an integer number with no more than 7 digits"),
				<< Set Function(	// called when user commits data entry
					Function( { self },
						new = self << Get;
						If( Length( Char( new ) ) > 7,
							self << Set( last ),
							last = new
						);
					);
				)
			)
		)
	)
);

View solution in original post

jthi
Super User

Re: How to limit the user entry to 7 digits in NumberEditBox?

There are different ways of doing this and it depends on how you wish your UI to behave:

  • If user inserts too many numbers, thrown an error message
  • If user inserts too many numbers, set the value to maximum allowed number
  • If user inserts too many numbers, set the value to empty value (missing value)
  • If user inserts too many numbers, set the value to last "valid" value
  • ...

Then you have to decide when the value should be updated: on commit or on each number change?

 

Below are few options, these can be combined as needed

 

View more...
Names Default To Here(1);

nw = New Window("Example",
	Lineup Box(N Col(2),
	
		Text Box("Set to max value on COMMIT:"),
		Number Edit Box(
			.
			, 10
			, << Set Maximum(9999999)
			, << Set Exclude Maximum(0)
			, << Set Integer Only(1)
		),
		
		Text Box("Set to last COMMITTED value on COMMIT:"),
		cb = Context Box(
			box:last_val = .;
			Number Edit Box(
				.
				, 10
				, << Set Function(function({this},
					If((this << get) >= 10000000,
						this << set(box:last_val)
					,
						box:last_val = this << get;
					)
				))
			)
		),
		
		Text Box("Throw on COMMIT"),
		cb = Context Box(
			box:last_val = .;
			Number Edit Box(
				.
				, 10
				, << Set Function(function({this},
					If((this << get) >= 10000000,
						this << set(box:last_val);
						Throw("No values longer than 7 digits allowed");
					,	
						box:last_val = this << get;
					)
				))
			)
		),
		
		Text Box("Set to last changed value on change and break focus:"),
		cb = Context Box(
			box:last_val = .;
			Number Edit Box(
				.
				, 10
				, << Set Number Changed(function({this, val},
					If((val) >= 10000000,
						this << set(box:last_val);
						box:mb << Set Focus(1); // to break focus from number edit box
					,
						box:last_val = val;
					)
				))
			),
			Unlineup Box(box:mb = Mouse Box());
		)
	)
);

 

 

-Jarmo

View solution in original post

8 REPLIES 8

Re: How to limit the user entry to 7 digits in NumberEditBox?

You can start in this direction. 

Names Default to Here( 1 );

last = eon = 0;

New Window( "Only Seven",
	Outline Box( "Enter EON",
		Line Up Box( N Col( 2 ),
			Text Box( "System EON:" ),
			neb = Number Edit Box( eon,
				<< Set Integer Only( 1 ),
				<< Set Minimum( 0 ),
				<< Set Tip( "Enter an integer number with no more than 7 digits")
				<< Set Number Changed(
					Function( { self, number },
						If( Length( Char( number ) ) > 7,
							self << Set( last ),
							last = number
						);
					);
				)
			)
		)
	)
)
PunitPanjwani
Level II

Re: How to limit the user entry to 7 digits in NumberEditBox?

Thanks Mark!

 

I modified the code as shown below, but still no success. Do you think its a big in JMP software?

Names Default to Here( 1 );

last = eon = 0;

New Window( "Only Seven",
    Outline Box( "Enter EON",
        Line Up Box( N Col( 2 ),
            Text Box( "System EON:" ),
            neb = Number Edit Box( eon,
                << Set Integer Only( 1 ),
                << Set Minimum( 0 ),
                << Set Tip( "Enter an integer number with no more than 7 digits")
                << Set Number Changed(
                    Function( { self, number },
                        If( Length( Char( number ) ) > 7,
                            self << Set( last ),
                            last = number
                        );
                    );
                ),
                << Set Max Length(7) // Limit the number of digits to 7
            )
        )
    )
)

Re: How to limit the user entry to 7 digits in NumberEditBox?

Where did you find this message:

<< Set Max Length(7) // Limit the number of digits to 7

I do not see it in the protocol for a Number Edit Box.

Re: How to limit the user entry to 7 digits in NumberEditBox?

Hi @PunitPanjwani 

This is a modified version of the example of set number changed() and get number changed() in the Scripting Index. I think this gets you pretty close to your target:

 

Names Default To Here( 1 );
New Window( "Example",
	numBox = Number Edit Box(
		.,
		10,
		<< set number changed(
			Function( { thisBox, value }, /* put my value into my sibling's display */
				if( length( char( value ) ) > 7,
					// > 7 digits
					thisBox << set( . );
					( thisBox << sib ) << settext( "Too many digits" ),
				
					// <= 7 digits
					( thisBox << sib ) << settext( char( value ) )
				)
			)
		)
	),
	Text Box( "" )/* here's the sibling box, waiting to show a message */
);
numBox << get number changed()

 

-Scott

Re: How to limit the user entry to 7 digits in NumberEditBox?

This version requires the user to commit the changes to the number.

Names Default to Here( 1 );

last = eon = 0;

New Window( "Only Seven",
	Outline Box( "Enter EON",
		Line Up Box( N Col( 2 ),
			Text Box( "System EON:" ),
			neb = Number Edit Box( eon,
				<< Set Integer Only( 1 ),
				<< Set Minimum( 0 ),
				<< Set Tip( "Enter an integer number with no more than 7 digits"),
				<< Set Function(	// called when user commits data entry
					Function( { self },
						new = self << Get;
						If( Length( Char( new ) ) > 7,
							self << Set( last ),
							last = new
						);
					);
				)
			)
		)
	)
);
PunitPanjwani
Level II

Re: How to limit the user entry to 7 digits in NumberEditBox?

Thank you, Mark!

jthi
Super User

Re: How to limit the user entry to 7 digits in NumberEditBox?

There are different ways of doing this and it depends on how you wish your UI to behave:

  • If user inserts too many numbers, thrown an error message
  • If user inserts too many numbers, set the value to maximum allowed number
  • If user inserts too many numbers, set the value to empty value (missing value)
  • If user inserts too many numbers, set the value to last "valid" value
  • ...

Then you have to decide when the value should be updated: on commit or on each number change?

 

Below are few options, these can be combined as needed

 

View more...
Names Default To Here(1);

nw = New Window("Example",
	Lineup Box(N Col(2),
	
		Text Box("Set to max value on COMMIT:"),
		Number Edit Box(
			.
			, 10
			, << Set Maximum(9999999)
			, << Set Exclude Maximum(0)
			, << Set Integer Only(1)
		),
		
		Text Box("Set to last COMMITTED value on COMMIT:"),
		cb = Context Box(
			box:last_val = .;
			Number Edit Box(
				.
				, 10
				, << Set Function(function({this},
					If((this << get) >= 10000000,
						this << set(box:last_val)
					,
						box:last_val = this << get;
					)
				))
			)
		),
		
		Text Box("Throw on COMMIT"),
		cb = Context Box(
			box:last_val = .;
			Number Edit Box(
				.
				, 10
				, << Set Function(function({this},
					If((this << get) >= 10000000,
						this << set(box:last_val);
						Throw("No values longer than 7 digits allowed");
					,	
						box:last_val = this << get;
					)
				))
			)
		),
		
		Text Box("Set to last changed value on change and break focus:"),
		cb = Context Box(
			box:last_val = .;
			Number Edit Box(
				.
				, 10
				, << Set Number Changed(function({this, val},
					If((val) >= 10000000,
						this << set(box:last_val);
						box:mb << Set Focus(1); // to break focus from number edit box
					,
						box:last_val = val;
					)
				))
			),
			Unlineup Box(box:mb = Mouse Box());
		)
	)
);

 

 

-Jarmo
PunitPanjwani
Level II

Re: How to limit the user entry to 7 digits in NumberEditBox?

Thank you, Jarmo!