Skip to content

Commit b0182d7

Browse files
ryanneufeldgnarf
authored andcommitted
Spinner: modified _spin and _setOption to call new method _trimValue to check for min/max values. Fixed #7264 - Spinner returns values beyond min and max, off by one
1 parent e549e18 commit b0182d7

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

ui/jquery.ui.spinner.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,29 @@ $.widget( "ui.spinner", {
258258
: 2
259259
: 1);
260260

261+
// clamp the new value
262+
newVal = this._trimValue( newVal );
263+
261264
if ( this._trigger( "spin", event, { value: newVal } ) !== false) {
262265
this.value( newVal );
263266
this.counter++;
264267
}
265268
},
266269

270+
_trimValue: function( value ) {
271+
var options = this.options;
272+
273+
if ( value > options.max) {
274+
return options.max;
275+
}
276+
277+
if ( value < options.min ) {
278+
return options.min;
279+
}
280+
281+
return value;
282+
},
283+
267284
_stop: function( event ) {
268285
this.counter = 0;
269286
if ( this.timer ) {
@@ -280,13 +297,7 @@ $.widget( "ui.spinner", {
280297

281298
_setOption: function( key, value ) {
282299
if ( key === "value") {
283-
value = this._parse( value );
284-
if ( value < this.options.min ) {
285-
value = this.options.min;
286-
}
287-
if ( value > this.options.max ) {
288-
value = this.options.max;
289-
}
300+
value = this._trimValue( this._parse(value) );
290301
}
291302

292303
if ( key === "disabled" ) {

0 commit comments

Comments
 (0)