Skip to content

Commit b7273b6

Browse files
committed
Slider: modified , so that slider value can not be set more than max.Fixed #9376 - Slider: Changed _max to max
1 parent fa23894 commit b7273b6

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

tests/unit/slider/slider_options.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ test( "disabled", function(){
4040
});
4141

4242
test( "max", function() {
43-
expect( 2 );
43+
expect( 4 );
4444
element = $( "<div></div>" );
4545

4646
options = {
@@ -52,8 +52,24 @@ test( "max", function() {
5252
};
5353

5454
element.slider( options );
55-
ok(element.slider( "option", "value" ) === options.value, "value option is not contained by max" );
56-
ok(element.slider( "value" ) === options.max, "value method is contained by max" );
55+
ok( element.slider( "option", "value" ) === options.value, "value option is not contained by max" );
56+
ok( element.slider( "value" ) === options.max, "value method is contained by max" );
57+
58+
options = {
59+
max: 9,
60+
min: 1,
61+
orientation: "horizontal",
62+
step: 3,
63+
value: 8.75
64+
};
65+
66+
element.slider( options );
67+
ok( element.slider( "value" ) === 7, "value method is within max, edge Case" );
68+
69+
options.step = 2;
70+
71+
element.slider( options );
72+
ok( element.slider( "value" ) === options.max, "value method will max, step is changed" );
5773
element.slider( "destroy" );
5874

5975
});

ui/slider.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ return $.widget( "ui.slider", $.ui.mouse, {
5858
this._handleIndex = null;
5959
this._detectOrientation();
6060
this._mouseInit();
61+
this._calculateNewMax();
6162

6263
this.element
6364
.addClass( "ui-slider" +
@@ -470,9 +471,11 @@ return $.widget( "ui.slider", $.ui.mouse, {
470471
}
471472
this._animateOff = false;
472473
break;
474+
case "step":
473475
case "min":
474476
case "max":
475477
this._animateOff = true;
478+
this._calculateNewMax();
476479
this._refreshValue();
477480
this._animateOff = false;
478481
break;
@@ -541,12 +544,22 @@ return $.widget( "ui.slider", $.ui.mouse, {
541544
return parseFloat( alignValue.toFixed(5) );
542545
},
543546

547+
_calculateNewMax: function() {
548+
var max = this._valueMin(),
549+
step = this.options.step;
550+
551+
while ( max + step <= this.options.max ) {
552+
max = max + step;
553+
}
554+
this.max = max;
555+
},
556+
544557
_valueMin: function() {
545558
return this.options.min;
546559
},
547560

548561
_valueMax: function() {
549-
return this.options.max;
562+
return this.max;
550563
},
551564

552565
_refreshValue: function() {

0 commit comments

Comments
 (0)