Ticket #4124 (closed bug: fixed)

Opened 6 years ago

Last modified 5 years ago

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

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

floatbugjquery.png Download (14.6 KB) - added by electrawn 6 years ago.
Picture of firebug console output

Change History

Changed 6 years ago by electrawn

Picture of firebug console output

comment:1 Changed 6 years ago by electrawn

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

comment:2 Changed 6 years ago by rdworth

  • Version changed from 1.5.3 to 1.6rc6

comment:3 Changed 6 years ago by scott.gonzalez

  • Summary changed from Value returned by slider is not always integer. to 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.

comment:4 Changed 6 years ago by paul

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

Fixed in r2089.

Note: See TracTickets for help on using tickets.