#5583 closed bug (fixed)
Slider displays negative fractional values incorrectly
Reported by: | evgeny | Owned by: | |
---|---|---|---|
Priority: | critical | Milestone: | 1.8.2 |
Component: | ui.slider | Version: | 1.8.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Create a slider with the minimum and maximum values set to negative values less than 1, eg. -0.7 to -0.5 with a step of 0.1. The slider handle is displayed in the wrong position and can actually be outside of the slider div. Repro attached.
This works in 1.8rc3, but is broken in 1.8.1.
Attachments (1)
Change History (4)
Changed 13 years ago by
Attachment: | slider-test.html added |
---|
comment:1 Changed 13 years ago by
I think it's bug.
See:
jQuery UI 1.8.1
jquery.ui.slider.js
Problem:
line 598 (ui.slider _trimAlignValue)
if ( valModStep >= ( step / 2 ) ) { alignValue += step; }
"valModStep" may be negative value (when val is negative).
Test Code:
window.alert(-7 % 0.3);
Workaround:
line 587 (ui.slider _trimAlignValue)
_trimAlignValue: function( val ) { + var step = this.options.step; + if (step > 0) { + var valModStep = val % step; + val -= valModStep; + if (Math.abs(valModStep) * 2 >= step) { + val += (valModStep > 0) ? step : (-step); + } + val = parseFloat( val.toFixed(5) ); + } if ( val < this._valueMin() ) { return this._valueMin(); } if ( val > this._valueMax() ) { return this._valueMax(); } - var step = this.options.step, - valModStep = val % step, - alignValue = val - valModStep; - - if ( valModStep >= ( step / 2 ) ) { - alignValue += step; - } // Since JavaScript has problems with large floats, round // the final value to 5 digits after the decimal point (see #4124) - return parseFloat( alignValue.toFixed(5) ); + return val; },
may work.
The "step-aligned" value should be between min and max.
comment:3 Changed 13 years ago by
Milestone: | TBD → 1.8.2 |
---|
Note: See
TracTickets for help on using
tickets.
Test case