Skip to main content

Bug Tracker

Side navigation

#2589 closed bug (fixed)

Opened March 26, 2008 04:54PM UTC

Closed May 04, 2008 08:48AM UTC

Last modified March 15, 2012 09:21AM UTC

ui.slider.js range problem getting handle values

Reported by: norbert Owned by: joern
Priority: major Milestone: 1.2.4
Component: ui Version: 1.2.3
Keywords: Cc:
Blocked by: Blocking:
Description

I am using the latest ui.slider.js (revision 5107) and have created a slider with two handles and a range:

$("#MyDiv").slider( {

'range': true,

'stepping': 1,

'minValue': 1,

'maxValue': 10,

'startValue': [1,10],

'stop': function(){

console.debug( $(this).slider('value') );

}

} );

Everything works fine until I move one of the handles. The console.debug statement in my stop event listener reported the correct value. However, if I try to retrieve the value of the range handles to send to the server using $("#MyDiv").slider('value', 0) or $("#MyDiv").slider('value', 1), I always got a very unhelpful JavaScript error:

Exception... "Could not convert JavaScript argument" nsresult:

"0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)", etc.

This error can be reproduced quite easily in the jQuery UI slider demo page (type $('#example3').slider('value', 0) in FireBug after loading the page).

I have patiently debugged the error and have located the problem in

line 173 of the ui.slider.js (revision 5107):

var value = ((parseInt($(handle != undefined ? this.handle[handle] || handle : this.currentHandle).css(this.properties[0]),10) /

(this.size() - this.handleSize())) * this.options.realMaxValue) +

this.options.minValue;

Since the this.handle array length is 2, line 172 does not set the

this.currentHandle:

if(this.handle.length == 1) this.currentHandle = this.handle;

That means that, when this.handleSize() is called without any

parameters in line 173, the function tries to use this.currentHandle

but, since it is not set, an error occurs.

To solve the problem I suggest changing line 173 to:

var value = ((parseInt($(handle != undefined ? this.handle[handle] || handle : this.currentHandle).css(this.properties[0]),10) /

(this.size() - this.handleSize(handle != undefined ? handle : null))) * this.options.realMaxValue) + this.options.minValue;

Or, in summary, we need to call the this.handleSize() function with the handle index parameter if it has been provided: this.handleSize(handle != undefined ? handle : null).

There might be other instances were the this.handleSize() function is called that might need a similar revision, but I haven't found any myself.

Attachments (0)
Change History (2)

Changed March 27, 2008 02:32PM UTC by paul comment:1

owner: pauljoern

Changed May 04, 2008 08:48AM UTC by paul comment:2

resolution: → fixed
status: newclosed

Should work now.