default value calculation error
grajendran-cricut opened this issue · 8 comments
I have used rangeslider and as per the documentation, the value is set to default by min + (max-min)/2;
However if I have min=100, max=350, as per this calculation it should have set 225 but my slider having 230?
100 + (350-100)/2 => 100 + 125 => 225
I tried to apply ceil/round etc but I could not fin how range slider got this value of 230?
Also, even if I set value after initializing,then updating the slider with 'update',true the value still having the calculated value.
@grajendran-cricut here is a really basic example and for me everything looks like expected here.
@andreruffert ,
Thanks for the response. I gone through that but still i have one issue which I want to describe
I have set range in html page with below settings
As per the rangeslider documentation, it will set 2000 as default value.
Next, on some event I am programmatically setting min,max,value from db using jquery like below
$(sliderControlId).prop('min', minFromDb);
$(sliderControlId).prop('max', maxFromDb);
$(sliderControlId).val(baseValueFromDb).change(); // note that here i am NOT setting min + (max-min)/2
$(sliderControlId).rangeslider('update', true);
I noticed that min and max are getting updated right, but the value is set as a different value.
for eg:
if I get db values as follows
min=70
max=350
base=175
the slider is setting 200 for value.(which i could not understand). I tried to destroy and initialize again it did not worked. I tried to set prop('value') but still it is not updating.
Next, without moving the slider at all, i try to read the default value, but it is returned as 210 which is 70 + (350-70)/2 = 70 + 140
When I move the slider, the values are getting updated and returns right value.
Here is another example for programatic attribute + value changes.
I hope this makes it a bit more clear.
let me check that too
@andreruffert , Just noticed that this got closed. I got into other issues and restarted the slider changes from last week and noticed that issue is re-appearing.
I have created a sample app in codepen in below URL
https://codepen.io/guhanath/pen/zYYGpbo
It is similar to https://codepen.io/andreruffert/pen/qdWWZP
I just set the value randomly and tried to fetch the value. As per my understanding, the value that I have set should be returned but it returns different value
for ex:
// set some random value
$r.val(25).change();
// get the value
console.log($r.val());
// the value is different from what is set -> returning 30. Should it return 25?
Am I doing anything wrong here? In other words, how can I set the value attribute to be something different that min + max-min/2 calculated value during initialization
Is there a way that I can set attribute for value similar to "min"/"max"
@grajendran-cricut in your example you have set these element attributes:
min
: 0
max
: 100
step
: 10
Now if you set a value to be 25
the plugin will just calculate the closest valid value because you set the step
to 10
. In this case the value will be 30
.
The step
attribute is crucial for the value calculation.
If you want 25
to be a valid value
set the step
to e.g. 5
.
Does this make sense?
@andreruffert , thanks for the update so quickly. In this example, the value will be 50 by default/calculated. Is it possible that I can set to different value(say 40) during initialization.
By the same logic described above with step = 10, will it go to 30 or 20 when we try to set the value between 20 - 25 and 25-30.
Sorry to ask these questions, I have used the slider and I want to know the cause/reason so that I can prepare myself for bugs.