Skip to main content

Search and Top Navigation

#5583 closed bug (fixed)

Opened May 05, 2010 05:10AM UTC

Closed May 11, 2010 12:18PM UTC

Last modified May 20, 2010 11:16AM UTC

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 (0.5 KB) - added by evgeny May 05, 2010 05:10AM UTC.

    Test case

Change History (3)

Changed May 11, 2010 11:45AM UTC by watanabe comment:1

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.

Changed May 11, 2010 12:18PM UTC by rdworth comment:2

resolution: → fixed
status: newclosed

Fixed in 34912bc

Changed May 20, 2010 11:16AM UTC by rdworth comment:3

milestone: TBD1.8.2