Skip to main content

Search and Top Navigation

#4124 closed bug (fixed)

Opened February 11, 2009 04:37PM UTC

Closed February 17, 2009 01:01PM UTC

Last modified February 02, 2010 07:05AM UTC

Value should always be constrained to valid step values

Reported by: electrawn Owned by:
Priority: critical Milestone: 1.7
Component: ui.slider Version: 1.6rc6
Keywords: Cc:
Blocked by: Blocking:
Description

Firefox 3.06, Windows XP 32Bit

Most of the time the slider value will return an integer, on occasional use, especially around the 2 mark, the code will break and return 1.99999998.

This screws up using a jquery wildcard to change the values of divs to show and hide elements. The change event code should hide all non relevant divs and then show() the correct one. I've left debug code in there to output the slider value to console.

I would imagine that the value function probably needs to be run through parseInt() before returning?

Snippet to reproduce:

Watch javascript console for occasional return of 1.99999998

Style from css

#slider {

width: 535px;

margin: 15px;

border: 1px solid #AAAAAA;

}

.sliderdesc{

height: 200px;

}

<script language="JavaScript" type="text/JavaScript">

$(document).ready(function() {

$("#sliderdesc-<%=slider%>").show();

$("#slider").slider({

value:<%=slider%>,

min: 1,

max: 5,

step: 1,

change: function(event, ui) {

$("div[id*='sliderdesc-']").css("display", "none").filter("#sliderdesc-" + $("#slider").slider("value")).show();

console.info($("#slider").slider("value"));

}

});

<h2>Preference Wizard</h2>

<div class="sliderdesc">

<div id="sliderdesc-1" style="display:none">

<h3>Everything</h3>

<p>Desc 1</p>

</div>

<div id="sliderdesc-2" style="display:none">

<h3>Custom: Automatic</h3>

<p>Desc 2</p>

</div>

<div id="sliderdesc-3" style="display:none">

<h3>Custom: Single Map</h3>

<p>Desc 3</p>

</div>

<div id="sliderdesc-4" style="display:none">

<h3>Custom: Full Control</h3>

<p>Desc 4 </p>

</div>

<div id="sliderdesc-5" style="display:none">

<h3>Nothing</h3>

<p>Desc 5</p>

</div>

</div>

<div id="slider" ></div>

<table width="675px">

<thead>

<tr>

<th width="20%"><span class="ui-icon ui-icon-triangle-1-n"></span></th>

<th width="20%"><span class="ui-icon ui-icon-triangle-1-n" ></span></th>

<th width="20%"><span class="ui-icon ui-icon-triangle-1-n"></span></th>

<th width="20%"><span class="ui-icon ui-icon-triangle-1-n"></span></th>

<th width="20%"><span class="ui-icon ui-icon-triangle-1-n"></span></th>

</tr>

</thead>

<tbody>

<tr>

<td>Everything</td>

<td>Custom:<br> Automatic</td>

<td>Custom:<br> Single Map</td>

<td>Custom:<br> Full Control</td>

<td>Nothing</td>

</tr>

</tbody>

</table>

Attachments (1)
  • floatbugjquery.png (14.6 KB) - added by electrawn February 11, 2009 04:38PM UTC.

    Picture of firebug console output

Change History (4)

Changed February 13, 2009 05:39PM UTC by electrawn comment:1

Looks like I am actually on 1.6rc6

The fix may be something along the lines of this in _value:

var val = Math.round(this.options.value);

Changed February 16, 2009 09:38AM UTC by rdworth comment:2

version: 1.5.31.6rc6

Changed February 17, 2009 02:22AM UTC by scottgonzalez comment:3

summary: Value returned by slider is not always integer.Value should always be constrained to valid step values

Non-integer values are valid, but only if the min + step combination allow them. Slider needs to be updated to enforce the step constraint. The HTML5 spec has a good description of how values should be dealt with.

Changed February 17, 2009 01:01PM UTC by paul comment:4

resolution: → fixed
status: newclosed

Fixed in r2089.