Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#7989 closed bug (notabug)

Error in Slider

Reported by: darshana Owned by:
Priority: minor Milestone: 1.9.0
Component: ui.slider Version: 1.8.16
Keywords: Cc:
Blocked by: Blocking:

Description

$( "#temperature" ).slider({ range:"min",min: 0,value:1,max: 1,step: 0.01,animate: true,orientation: "vertical", change: function( event, ui ) {alert($( "#temperature" ).slider("value" ));},slide: function( event, ui ) {$( "#temp_val" ).val($( "#temperature" ).slider("value" ));}}); });

As I slide the slider, the value gets displayed in a textbox. However, the 2 values (one being showed in the alert box and the ones being displayed in textbox) are not the same... difference between them is random as well, sometimes .01 and sometimes .02.

Thanks a lot.. Biggest issue is that I have set the maximum as max=1 but when I pull the slider to its highest position, the slide event gives 0.99 while the onchange event gives 1. the Slide event is not working properly because if max=1, the slider gives these values [0.99,1,0.99,0.98,0.97,...] I need to play around to get the 1.. Can someone please help me out if I am getting something wrong?

Change History (4)

comment:1 Changed 7 years ago by Scott González

Resolution: invalid
Status: newclosed

The value is not updated until after the slide event. That's why the highest value you're seeing is 0.99. When you do see it alert 1, it's because you've already reached the max and have moved one step lower.

comment:2 Changed 7 years ago by darshana

Hi could you please explain it to me again? I cnt get it.. sorry..

I am using the slider for a simulation model, so its like when the handle is being used, the slide event helps to indicate which is the current slider value. I used the change event so as to trigger a serverside call, which takes the slider value being displayed in the textbox as parameter.

Can you guide me as to whether the choice of event trigger is appropriate or not?

Thanks a lot Scott :)

comment:3 Changed 7 years ago by Scott González

From the documentation for the slide event: "This event is triggered on every mouse move during slide. Use ui.value (single-handled sliders) to obtain the value of the current handle."

You want to know the value that the slider is moving to, not the value that the slider currently has. You need to use ui.value from the event to get that.

$( "#temperature" ).slider({
    slide: function( event, ui ) {
        $( "#temp_val" ).val( ui.value );
    }
});

comment:4 Changed 7 years ago by darshana

Thanks a lot.. I got it straight now :)

Note: See TracTickets for help on using tickets.