Opened 10 years ago

Closed 10 years ago

Last modified 9 years ago

#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)

slider-test.html (517 bytes) - added by evgeny 10 years ago.
Test case

Download all attachments as: .zip

Change History (4)

Changed 10 years ago by evgeny

Attachment: slider-test.html added

Test case

comment:1 in reply to:  description Changed 10 years ago by watanabe

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:2 Changed 10 years ago by rdworth

Resolution: fixed
Status: newclosed

Fixed in 34912bc

comment:3 Changed 9 years ago by rdworth

Milestone: TBD1.8.2
Note: See TracTickets for help on using tickets.