Skip to content

ui.slider: modified , so that slider value can not be set more than max.... #1016

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

Closed
wants to merge 2 commits into from

Conversation

dekajp
Copy link
Contributor

@dekajp dekajp commented Jun 26, 2013

...Fixed #9376 - ui.slider: On mouse move slider sets value more than max

@scottgonzalez
Copy link
Member

We shouldn't be calculating the max on every move/change. We should calculate once, whenever min, step, or max changes. This should be done in _create() and _setOptions() (I'm fine if you use _setOption() instead of _setOptions() for now since we haven't optimized this code yet).

Also, we already have a function to abstract out the getting of the max value. You shouldn't be adding a new function, you should be changing _valueMax() to return the valid max (the value calculated above).

@scottgonzalez
Copy link
Member

Please also take some time to read our style guide as there are many style violations in this code.

@dekajp
Copy link
Contributor Author

dekajp commented Jun 26, 2013

So are you recommending - override options.max in _create() and _setOptions() using the calculation i added ?

@scottgonzalez
Copy link
Member

No, calculate the max and store it in a different property on the plugin. Then have _valueMax() return that value.

@dekajp
Copy link
Contributor Author

dekajp commented Jun 26, 2013

Will it be ok ? if _valueMax() do calculate Max and retains it (mnemonically) . something i did in my _calculatedmax .

@scottgonzalez
Copy link
Member

I'd much rather you follow existing conventions and calculate it when it actually changes.

@dekajp
Copy link
Contributor Author

dekajp commented Jun 27, 2013

@scottgonzalez submitted new code and ran grunt lint and grunt build

@@ -531,12 +533,29 @@ $.widget( "ui.slider", $.ui.mouse, {
return parseFloat( alignValue.toFixed(5) );
},

_calculateNewMax: function() {
var newmax,
step = ( this.options.step > 0 ) ? this.options.step : 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't be guarding against this. If the step is set to a negative number, then we can force the option to 1. But unless we have a bug report for this, I'd rather just skip it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i removed this check in new commit - 90ca5b7436d88bff98ce4c6d01b51236cbb88fe9

@scottgonzalez
Copy link
Member

You still need to handle the case of step being changed.

@@ -56,6 +56,44 @@ test( "max", function() {
ok(element.slider( "value" ) === options.max, "value method is contained by max" );
element.slider( "destroy" );

element = $( "<div></div>" );

options = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't redefine options. Just update the one option you care about so that it's clear what you're testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@scottgonzalez
Copy link
Member

Don't be discouraged by the large number of comments, it's mostly really small stuff. This is getting really close. Thanks for sticking with this.

@dekajp
Copy link
Contributor Author

dekajp commented Jun 27, 2013

sure :) i will implement the changes

@dekajp
Copy link
Contributor Author

dekajp commented Jun 28, 2013

@scottgonzalez i updated the code . hope this time i get it right

@dekajp
Copy link
Contributor Author

dekajp commented Oct 19, 2013

Rebased commits into 1 commit. updated the email address.

@tjvantoll
Copy link
Member

@dekajp I'm assuming this is ready for us to take a look at again correct?

@dekajp
Copy link
Contributor Author

dekajp commented Oct 22, 2013

@tjvantoll yes

@tjvantoll
Copy link
Member

👍

@@ -531,12 +534,22 @@ $.widget( "ui.slider", $.ui.mouse, {
return parseFloat( alignValue.toFixed(5) );
},

_calculateNewMax: function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be done with math instead of a loop (untested):

using division:

var steps = Math.floor( ( this.options.max - this._valueMin() ) / this.options.step );
this.max = this._valueMin() + ( steps * this.options.step );

using remainders:

var remainder = ( this.options.max - this._valueMin() ) % this.options.step;
this.max = this.options.max - remainder;

@mikesherov
Copy link
Member

@dekajp can you update this PR to use math instead of a loop?

@dekajp
Copy link
Contributor Author

dekajp commented Feb 6, 2014

@mikesherov - removed loop

@jzaefferer
Copy link
Member

@mikesherov @tjvantoll can you take a look at this again? Should be good to land.

dekajp added 2 commits October 7, 2014 23:25
…i.slider: On mouse move slider sets value more than max
@dekajp dekajp force-pushed the 9376-Slider-Max-defect-v6 branch from ada0337 to 8932df7 Compare October 8, 2014 03:27
@dekajp
Copy link
Contributor Author

dekajp commented Oct 8, 2014

Rebased /cc @mikesherov @tjvantoll @jzaefferer

@tjvantoll
Copy link
Member

This fix looks good to me and I verified it works. All of @scottgonzalez's and @mikesherov's comment were addressed, so I'm going to land this.

@tjvantoll tjvantoll closed this in 6833a31 Oct 8, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants