Ticket #5583 (closed bug: fixed)

Opened 5 years ago

Last modified 5 years ago

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:
Blocking: Blocked by:

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

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

Change History

Changed 5 years ago by evgeny

Test case

comment:1 in reply to: ↑ description Changed 5 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 5 years ago by rdworth

  • Status changed from new to closed
  • Resolution set to fixed

Fixed in  34912bc

comment:3 Changed 5 years ago by rdworth

  • Milestone changed from TBD to 1.8.2
Note: See TracTickets for help on using tickets.