Skip to content

Commit 7c921d3

Browse files
committed
Slider: Fix to restrict handle values when set programmatically.
Fixes #3762 - Slider: handles not restricted properly when set programmatically
1 parent 8c75382 commit 7c921d3

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

ui/slider.js

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ return $.widget( "ui.slider", $.ui.mouse, {
6767
this._detectOrientation();
6868
this._mouseInit();
6969
this._calculateNewMax();
70+
this._cleanValues();
7071

7172
this.element
7273
.addClass( "ui-slider" +
@@ -159,12 +160,28 @@ return $.widget( "ui.slider", $.ui.mouse, {
159160

160161
_cleanValues: function( index, newValue ) {
161162
var values,
162-
i = 0 ;
163+
i = 0;
164+
165+
if ( this.options.range === true ){
166+
if ( arguments.length === 2 ) {
167+
values = this.options.values;
168+
if ( index === 0 && newValue < this._valueMin() ){
169+
newValue = this._valueMin();
170+
}else if ( index === 1 && newValue > this._valueMax() ){
171+
newValue = this._valueMax();
172+
}
173+
174+
if ( index === 0 && newValue > values[ 1 ] ) {
175+
newValue = values[ 1 ];
176+
}else if ( index === 1 && newValue < values[ 0 ] ) {
177+
newValue = values[ 0 ];
178+
}
179+
return newValue;
180+
}
163181

164-
if ( $.isArray( arguments[ 0 ] ) ) {
165182
values = arguments[ 0 ] || this.options.values;
166183
if ( values ) {
167-
for ( ; i < values.length; i++ ){
184+
for ( ; i < values.length; i++ ) {
168185
if ( values[ i ] < this._valueMin() ) {
169186
values[ i ] = this._valueMin();
170187
}
@@ -176,26 +193,19 @@ return $.widget( "ui.slider", $.ui.mouse, {
176193
if ( values[ 0 ] > values[ 1 ] ) {
177194
values[ 1 ] = values[ 0 ];
178195
}
179-
return values;
180-
}
181-
}
182-
183-
if ( arguments.length > 1 ) {
184-
values = this.options.values;
185-
if ( index === 0 && newValue < this._valueMin() ){
186-
newValue = this._valueMin();
187-
}else if ( index === 1 && newValue > this._valueMax() ){
188-
newValue = this._valueMax();
189-
}
190196

191-
if ( this.options.range === true && values.length === 2 ) {
192-
if ( index === 0 && newValue > values[ index + 1 ] ) {
193-
newValue = values[ index + 1 ];
194-
}else if ( index === 1 && newValue < values[ index - 1 ] ) {
195-
newValue = values[ index - 1 ];
197+
if ( arguments[ 0 ] ){
198+
return values;
199+
} else {
200+
this.options.values = values;
196201
}
197202
}
198-
return newValue;
203+
} else {
204+
if ( $.isArray( arguments[ 0 ] ) ) {
205+
return arguments[0];
206+
} else {
207+
return newValue;
208+
}
199209
}
200210
},
201211

@@ -465,7 +475,6 @@ return $.widget( "ui.slider", $.ui.mouse, {
465475
this._refreshValue();
466476
} else {
467477
if ( this.options.values && this.options.values.length ) {
468-
this.options.values = this._cleanValues( this.options.values );
469478
return this._values( index );
470479
} else {
471480
return this.value();

0 commit comments

Comments
 (0)