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
john_madden
Level VI

Number Edit Box on change script

I'm new to JSL and Application Builder, so bear with me.

I'm trying to build a dialog box that has a series paired Number Edit Boxes. One of each pair represents a "start" time and the other a corresponding "end" time:screenshot_386.png

 

I want to avoid the situation where the user puts in a "start" time later than the "end" time, or an "end" time prior to the "start" time.

My first thought was to add an "on change" script to each box, something like this for the "start" box:

If( (Start << Get) > (End << Get),
	End << Set( Start << Get )
);

and like this for the "end" box:

If( Start << Get > End << Get,
	Start << Set( End << Get )
);

But this doesn't work (in the sense that nothing happens when the unwanted condition occurs).

I'm probably doing something quite silly, but help would be appreciated. 

2 ACCEPTED SOLUTIONS

Accepted Solutions

Re: Number Edit Box on change script

You can do this by Setting the Min/Max values for both the start and end NumberEditBoxes within the SetFunction (instead of OnChange). 

New Window( "Example",
	Lineup Box( N Col( 2 ),
		Text Box( "Work Starts" ),
		Text Box( "Work Ends" ),
		start_neb = Number Edit Box(
			0,
			<<Set Format( Format( "h:m:s" ) ),
			<<Set Function(
				Function( {this},
					end_neb << Set Minimum( this << Get )
				)
			)
		),
		end_neb = Number Edit Box(
			0,
			<<Set Format( Format( "h:m:s" ) ),
			<<Set Function(
				Function( {this},
					start_neb << Set Maximum( this << Get )
				)
			)
		)
	)
);
Justin

View solution in original post

pmroz
Super User

Re: Number Edit Box on change script

You need to set up scripts to call for each of the number edit boxes.  I created a simple example:

 

start_time_neb: number edit box for the start time

end_time_neb: number edit box for the end time

 

I right-clicked on each of the number edit boxes and selected Scripts > Script (not Number changed).  Here are the scripts I added:


// This function is called when the number edit value is committed
start_time_nebScript=Function({this},{start_time_value, end_time_value},
	start_time_value = this << Get;
	end_time_value   = end_time_neb << get;
	
	if (!is missing(start_time_value) & !is missing(end_time_value),
		if (start_time_value > end_time_value,
			nw = new window("Error", << modal(),
				text box("The Start Time cannot be after the End Time")
			);
			this << set(.);
		);
	);
	
);


// This function is called when the number edit value is committed
end_time_nebScript=Function({this},{start_time_value, end_time_value},

	start_time_value = start_time_neb << get;
	end_time_value   = this << Get;
	
	if (!is missing(start_time_value) & !is missing(end_time_value),
		if (start_time_value > end_time_value,
			nw = new window("Error", << modal(),
				text box("The End Time cannot be before the Start Time")
			);
			this << set(.);
		);
	);
);

 

View solution in original post

8 REPLIES 8

Re: Number Edit Box on change script

You can do this by Setting the Min/Max values for both the start and end NumberEditBoxes within the SetFunction (instead of OnChange). 

New Window( "Example",
	Lineup Box( N Col( 2 ),
		Text Box( "Work Starts" ),
		Text Box( "Work Ends" ),
		start_neb = Number Edit Box(
			0,
			<<Set Format( Format( "h:m:s" ) ),
			<<Set Function(
				Function( {this},
					end_neb << Set Minimum( this << Get )
				)
			)
		),
		end_neb = Number Edit Box(
			0,
			<<Set Format( Format( "h:m:s" ) ),
			<<Set Function(
				Function( {this},
					start_neb << Set Maximum( this << Get )
				)
			)
		)
	)
);
Justin
David_Burnham
Super User (Alumni)

Re: Number Edit Box on change script

A couple of things to try: 

1. Look in the log window - although nothing appears to happen there may be an error being reported that will give you a clue 

2. Reduce the code to something as simple as possible.  This will help you figure out what works, what doesn't.  For example, this seems to work the way you describe:

 

New Window("Test",
		neb1 = NumberEditBox(0),
		neb2 = NumberEditBox(0)
);
neb1 << Set Function(
	If( (neb1 << Get) > (neb2 << Get),
		neb2 << Set( neb1 << Get )
	)
);
neb2 << Set Function(
	If( (neb1 << Get) > (neb2 << Get),
		neb1 << Set( neb2 << Get )
	)
);

 

-Dave
pmroz
Super User

Re: Number Edit Box on change script

You need to set up scripts to call for each of the number edit boxes.  I created a simple example:

 

start_time_neb: number edit box for the start time

end_time_neb: number edit box for the end time

 

I right-clicked on each of the number edit boxes and selected Scripts > Script (not Number changed).  Here are the scripts I added:


// This function is called when the number edit value is committed
start_time_nebScript=Function({this},{start_time_value, end_time_value},
	start_time_value = this << Get;
	end_time_value   = end_time_neb << get;
	
	if (!is missing(start_time_value) & !is missing(end_time_value),
		if (start_time_value > end_time_value,
			nw = new window("Error", << modal(),
				text box("The Start Time cannot be after the End Time")
			);
			this << set(.);
		);
	);
	
);


// This function is called when the number edit value is committed
end_time_nebScript=Function({this},{start_time_value, end_time_value},

	start_time_value = start_time_neb << get;
	end_time_value   = this << Get;
	
	if (!is missing(start_time_value) & !is missing(end_time_value),
		if (start_time_value > end_time_value,
			nw = new window("Error", << modal(),
				text box("The End Time cannot be before the Start Time")
			);
			this << set(.);
		);
	);
);

 

pmroz
Super User

Re: Number Edit Box on change script

Here's the example.  Created using JMP 13, so may not work in earlier versions.

john_madden
Level VI

Re: Number Edit Box on change script

Thanks, all of you for great suggestions. I haven't tried them all out yet, but I will as soon as I get a break from my "real" work.

 

In the meantime, I think at the root of a lot of my problems is that I haven't found detailed documentation for the App Builder (AB). It must exist, but I can't find it. Does anyone have a link? 

 

For example, I didn't know what the "Script" field in the Properties menu of AB was for, and I didn't make the connection with the Number Edit Box (NEB) documentation. I'm groping my way along here, obviously.

 

Another example of my confusion, the "Increment" entry field in the AB Properties pane for NEBs exists, but won't accept an entry. I could go on…

 

Like I say, some good documentation on AB, and also some excellent examples of complex modal dialog box scripts would be great. Also, is there a way to actually see the code that AB generates for the interface?

 

 

Craige_Hales
Super User

Re: Number Edit Box on change script

Yes, you can open the saved app builder files in a text editor, but the app builder gui is the only supported way for editing the file. (Still worth a look if you want to have an idea what happens when the script is opened.)

Here's some links to resources on the web.

https://community.jmp.com/t5/Discovery-Summit-2016/Building-Dashboards-and-Applications-Poster-and-T...

Craige
pmroz
Super User

Re: Number Edit Box on change script

Application Builder takes some time to learn, but it's worth it.  I've been using it since JMP version 10, and it gets better with each version.  I've attached a presentation I gave at the JMP Discovery 2013 JSL Roundtable which may be of some help.

 

john_madden
Level VI

Re: Number Edit Box on change script

Thanks for all the help guys!!!