PDA

View Full Version : Slider events


jpan
04-08-2004, 11:39 AM
Hi,

I have a vertical slider. When the user moves the tick along the vertical slider, the current value changes. I need to capture the event when the user let's go of the mouse. How can I do this??

Thank you,

James

vfunshteyn
04-08-2004, 11:45 AM
onmouseup should work, I would think.

jpan
04-08-2004, 11:47 AM
not quite...

I noticed that if I put in onmouseup, the event is only raised when the mouseup event happens on the slider track, not the slider tick...

vfunshteyn
04-08-2004, 11:54 AM
That makes sense. Try defining <method event="onvalue"> for your slider.

jpan
04-08-2004, 12:03 PM
I guess I really should have provided more info. I apologize for the uninformative question...

I *did* use onvalue... but this message came up in the debugger window:

base/baseslider.lzx:88: call to undefined method 'sendEvent'

What does this mean, and how I can correct this? Thanks again!

vfunshteyn
04-08-2004, 12:08 PM
The following code runs without any debugger warnings in LPS 2.1:


<canvas height="200" debug="true">
<slider x="20" y="20" width="300" value="50">
<method event="onvalue">
debug.write(this.value)
</method>
</slider>
</canvas>

jpan
04-08-2004, 12:11 PM
Sorry, I messed up. I put

<method name="onvalue">

instead of

<method event="onvalue">

Thank you very much for your help!

James

jpan
04-08-2004, 12:16 PM
oops, one last question:

I am capturing the value now as the user moves it. However, I need to make a request to a server based on the value the user selects, and if the user clicks on the slider tick and moves it up and down without letting go, the value should change but I don't want to make a request until the user lets go of the mouse. Is there a way I can capture that event?

Thanks again!

James

vfunshteyn
04-08-2004, 12:59 PM
If I understand the metaphor behind the slider component correctly, it is designed to give instant feedback when the thumb's position changes. Judging from the slider API, it's not granular enough to give you the kind of low level control that would allow the event of the mouse button released from the dragger to be caught. You could probably write your own version of slider based on this component, that would cause the mouseup event to be sent only when the pointer is over the thumb.

antun
04-08-2004, 02:12 PM
What you're looking for is something like an onselect event. There isn't one with the slider by default.

However remember that LZX is object-oriented, so you can do something like:


<canvas height="500" debug="true">
<slider x="20" y="20" width="300" value="50">
<method event="onmouseup" reference="subviews[0].thumb">
debug.write('Slider Selected: ' + this.value);
</method>
</slider>
</canvas>


(That's polymorphism at its finest). I knew to reference the thumb using subviews[0].thumb because I looked in the source code for the slider; on a Windows box:

C:\Program Files\Laszlo Presentation Server 2.1\jakarta-tomcat-4.1.12\webapps\lps-2.1\WEB-INF\lps\components\lz\slider.lzx

... where I noticed that the thumb instance lived inside of an un-named instance of slidertrack. Since it was un-named, I had to use the subviews[viewnum] syntax, but the thumb was named (thumb).

-Antun