cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
mjoner
Level VI

JSL: Slider Box Set Value

Hi everyone,

 

Here is the code from the Scripting Index for creating a Slider Box:

Names Default To Here( 1 );
sliderValue = .6;
New Window( "Example",
	Panel Box( "Slider Box",
		tb = Text Box( "Value: " || Char( sliderValue ) ),
		sb = Slider Box(
			0,
			1,
			sliderValue,
			tb << Set Text( "Value: " || Char( sliderValue ) )
		)
	)
);

 

If you run this example, you can right-click the slider to set a specific value:

mjoner_0-1613593250922.png

 

Let's suppose I set this to 0.8. If I do, the slider moves, but the script associated with the slider fails to execute. That is, the text box above the slider doesn't update.

 

Question 1: Why?

Question 2: Is there a different way to transfer the new value to the Text Box? I tried to convert the code to use the Set Function message but this didn't solve it.

 

I have observed that if you right click a slider in a Platform (such as Custom Profiler) and Set Value that the platform seems to respond correctly (slider and associated Text Edit Box both move as expected), so I can tell there is some way to do this in JSL. I just don't know what that is.

 

I'm running 15.2.1 Pro on a Mac.

 

Michael

2 ACCEPTED SOLUTIONS

Accepted Solutions
ih
Super User (Alumni) ih
Super User (Alumni)

Re: JSL: Slider Box Set Value

This doesn't address the underlying issue you identified with the script not triggering, but I often put a number edit box next to that value with a script to set the value of the slider.  That way if someone wants to set the value they are unlikely to right click on the slider as it is easier to just click on the text edit box.  Here is one way to incldue both, while also running some function when the slider moves or a new value is typed in:

 

    ih_0-1613594737809.png

 

Names Default To Here( 1 );
sliderValue = .6;

//Function that is called when either slider is moved or new value is typed in
dothisonchange = Function({val}, tb << Set Text( "Value: " || Char( val) ) );

New Window( "Example",
	Panel Box( "Slider Box",
		tb = Text Box( "Value: " || Char( sliderValue ) ),
		h list box(
			sb = Slider Box(
				0,
				1,
				sliderValue,
				//Set the number edit box and call the other function
				neb << Set( sliderValue );
				dothisonchange(sliderValue);
				
			),
			neb = Number Edit Box(
				sliderValue,
				3,
				<< Set function( Function( {this},
					sliderValue = this << Get;
					//Set the slider and call the other function
					sb << Set( sliderValue );
					dothisonchange(sliderValue);
				) )
			)
		)
	)
);

View solution in original post

MathStatChem
Level VI

Re: JSL: Slider Box Set Value

6 REPLIES 6
Jeff_Perkinson
Community Manager Community Manager

Re: JSL: Slider Box Set Value

Thanks for providing a clear example and question. It made it easy to verify that this is a bug in JMP 15 (perhaps earlier versions). The callback for the slider isn't being triggered on the Set Value. 

 

I also verified that we have fixed it in the upcoming JMP 16 release. 

 

There may be a tricky workaround you could code in JSL, but where you see it working in the built-in platforms it's not being done through JSL.

-Jeff

Re: JSL: Slider Box Set Value

I do not see a work-around because there is no way to associate an expression with the Set Value action. Here is a variation of the original script, but it doesn't work either because it is called when the slider is moved.

 

Names Default To Here( 1 );

sliderValue = .6;

New Window( "Example",
	Panel Box( "Slider Box",
		tb = Text Box( "Value: " || Char( sliderValue ) ),
		Slider Box( 0, 1, sliderValue,
			<< Set Function(
				Function( { me },
					tb << Set Text( "Value: " || Char( me << Get ) )

				)
			)
		)
	)
);
ih
Super User (Alumni) ih
Super User (Alumni)

Re: JSL: Slider Box Set Value

This doesn't address the underlying issue you identified with the script not triggering, but I often put a number edit box next to that value with a script to set the value of the slider.  That way if someone wants to set the value they are unlikely to right click on the slider as it is easier to just click on the text edit box.  Here is one way to incldue both, while also running some function when the slider moves or a new value is typed in:

 

    ih_0-1613594737809.png

 

Names Default To Here( 1 );
sliderValue = .6;

//Function that is called when either slider is moved or new value is typed in
dothisonchange = Function({val}, tb << Set Text( "Value: " || Char( val) ) );

New Window( "Example",
	Panel Box( "Slider Box",
		tb = Text Box( "Value: " || Char( sliderValue ) ),
		h list box(
			sb = Slider Box(
				0,
				1,
				sliderValue,
				//Set the number edit box and call the other function
				neb << Set( sliderValue );
				dothisonchange(sliderValue);
				
			),
			neb = Number Edit Box(
				sliderValue,
				3,
				<< Set function( Function( {this},
					sliderValue = this << Get;
					//Set the slider and call the other function
					sb << Set( sliderValue );
					dothisonchange(sliderValue);
				) )
			)
		)
	)
);
MathStatChem
Level VI

Re: JSL: Slider Box Set Value

You could also use this approach Combined and Connected Number Edit Box and Slider Box 

mjoner
Level VI

Re: JSL: Slider Box Set Value

Thanks. I knew about the Number Edit Box approach and am now leaning toward going that way. The linked thread from @MathStatChem sounds like a wishlist item to either create a new type of display box or to add some option to sliderbox that would optionally add a NEB control. I'm assuming that wishlist item has already been created.

MathStatChem
Level VI

Re: JSL: Slider Box Set Value

Yes, I did create the wishlist item. Combined and Connected Number Edit Box and Slider Box