Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default value calculation error #338

Closed
grajendran-cricut opened this issue Jul 30, 2019 · 8 comments
Closed

default value calculation error #338

grajendran-cricut opened this issue Jul 30, 2019 · 8 comments
Labels

Comments

@grajendran-cricut
Copy link

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?

@grajendran-cricut
Copy link
Author

Also, even if I set value after initializing,then updating the slider with 'update',true the value still having the calculated value.

@andreruffert
Copy link
Owner

@grajendran-cricut here is a really basic example and for me everything looks like expected here.

@grajendran-cricut
Copy link
Author

@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.

@andreruffert
Copy link
Owner

andreruffert commented Jul 31, 2019

Here is another example for programatic attribute + value changes.
I hope this makes it a bit more clear.

@grajendran-cricut
Copy link
Author

let me check that too

@grajendran-cricut
Copy link
Author

grajendran-cricut commented Oct 9, 2019

@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"

@andreruffert
Copy link
Owner

@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?

@grajendran-cricut
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants