Bug Tracker

Ticket #2589 (closed bug: fixed)

Opened 10 months ago

Last modified 8 months ago

ui.slider.js range problem getting handle values

Reported by: norbert Assigned to: joern
Type: bug Priority: major
Milestone: 1.2.4 Component: ui
Version: 1.2.3 Keywords:
Cc: Needs: Review

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

Change History

Changed 10 months ago by paul

  • owner changed from paul to joern

Changed 8 months ago by paul

  • status changed from new to closed
  • resolution set to fixed

Should work now.

Note: See TracTickets for help on using tickets.