Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery-UI slider - how to disable keyboard input?

in jQuery-UI Slider arrow keys move the slider handle (after the handle has been selected/clicked on), which is nice, but I don't want slider to handle keyboard (I use arrow keys on the page for another purpouse).

Any ideas how to disable keyboard events for jquery-ui slider?

like image 454
Petr Urban Avatar asked May 27 '10 14:05

Petr Urban


2 Answers

You can unbind the keydown event from the handle to do what you want, like this:

$("#slider").slider(); //create slider
$("#slider .ui-slider-handle").unbind('keydown'); //disable keyboard actions

You can see a demo here

like image 157
Nick Craver Avatar answered Oct 24 '22 04:10

Nick Craver


You can also automate the above solution like so:

$.prototype.slider_old = $.prototype.slider;
$.prototype.slider = function()
{
    var result = $.prototype.slider_old.apply(this, arguments);
    this.find(".ui-slider-handle").unbind("keydown"); // disable keyboard actions
    return result;
}

Just have this code run sometime before you make the "$(...).slider()" calls, and it should remove the keydown event for each one automatically, right after slider initialization.

like image 1
Venryx Avatar answered Oct 24 '22 04:10

Venryx