Ui Spinner Bug When Changing Value Using Mouse Up And Down
I added the decimal spinner to my site. My value was 56.20. When I change use mouse wheel up, I am expecting 57.20, but now it is showing 57:00. The function is shown below: &l
Solution 1:
I don't think it's a bug at all sorry to say, it's simply rounding up - I think this the part in the jQuery code within the spinner.js that actions the round up:
During the _spin()
:
value = this._adjustValue( value + step * this._increment( this.counter ) );
Calls _adjustValue()
:
_adjustValue: function( value ) {
var base, aboveMin,
options = this.options;
// make sure we're at a valid step// - find out where we are relative to the base (min or 0)
base = options.min !== null ? options.min : 0;
aboveMin = value - base;
// - round to the nearest step
aboveMin = Math.round(aboveMin / options.step) * options.step;
// - rounding is based on 0, so adjust back to our base
value = base + aboveMin;
// fix precision from bad JS floating point math
value = parseFloat( value.toFixed( this._precision() ) );
// clamp the valueif ( options.max !== null && value > options.max) {
return options.max;
}
if ( options.min !== null && value < options.min ) {
return options.min;
}
return value;
},
Source: jQuery UI GitHub
But what you could try, is catching the value before spinning & then re-adjusting the value after a completed spin, based on what you had before with the two callback events below:
var beforeSpin = 1.00;
$( "#spinner" ).spinner({
step: 1.10,
numberFormat: "n",
start: function( event, ui ) {
beforeSpin = ui.value;
},
//or stop: function(){}spin: function( event, ui ) {
//Do some re-value//funciton based on old value
}
});
That, or re-program the _adjustValue: function()
to your needs - Open source after all :)
Solution 2:
Everything looks good here, just set your step to 1.10.
Example:
$( "#spinner" ).spinner({
step: 1.10,
numberFormat: "n"
});
Peep the DEMO
I should add that you can adjust the increment value accordingly.
Post a Comment for "Ui Spinner Bug When Changing Value Using Mouse Up And Down"