Bug Tracker

Opened 16 years ago

Closed 15 years ago

Last modified 12 years ago

#2589 closed bug (fixed)

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:


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.

Change History (2)

comment:1 Changed 16 years ago by paul

Owner: changed from paul to joern

comment:2 Changed 15 years ago by paul

Resolution: fixed
Status: newclosed

Should work now.

Note: See TracTickets for help on using tickets.