Skip to content

Commit

Permalink
Spinner: modified _spin and _setOption to call new method _trimValue …
Browse files Browse the repository at this point in the history
…to check for min/max values. Fixed #7264 - Spinner returns values beyond min and max, off by one
  • Loading branch information
ryanneufeld authored and gnarf committed Jun 14, 2011
1 parent e549e18 commit b0182d7
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions ui/jquery.ui.spinner.js
Expand Up @@ -258,12 +258,29 @@ $.widget( "ui.spinner", {
: 2 : 2
: 1); : 1);


// clamp the new value
newVal = this._trimValue( newVal );

if ( this._trigger( "spin", event, { value: newVal } ) !== false) { if ( this._trigger( "spin", event, { value: newVal } ) !== false) {
this.value( newVal ); this.value( newVal );
this.counter++; this.counter++;
} }
}, },


_trimValue: function( value ) {
var options = this.options;

if ( value > options.max) {
return options.max;
}

if ( value < options.min ) {
return options.min;
}

return value;
},

_stop: function( event ) { _stop: function( event ) {
this.counter = 0; this.counter = 0;
if ( this.timer ) { if ( this.timer ) {
Expand All @@ -280,13 +297,7 @@ $.widget( "ui.spinner", {


_setOption: function( key, value ) { _setOption: function( key, value ) {
if ( key === "value") { if ( key === "value") {
value = this._parse( value ); value = this._trimValue( this._parse(value) );
if ( value < this.options.min ) {
value = this.options.min;
}
if ( value > this.options.max ) {
value = this.options.max;
}
} }


if ( key === "disabled" ) { if ( key === "disabled" ) {
Expand Down

0 comments on commit b0182d7

Please sign in to comment.