Update: jQuery UI Slider from a Select Element - now with ARIA Support

Posted by Scott on 04/16/2009

Topics:

We've updated our popular jQuery UI selectToUISlider plugin with ARIA support, making the jQuery UI slider widget more accessible to users on assistive devices. The plugin uses progressive enhancement to replace an already-functional HTML select element with a jQuery UI slider control, and adds a number of features for both visual users and those on assistive technologies.

What's This All About?

Our selectToUISlider plugin uses progressive enhancement to scrape the data from a select element (or two for a range) and generate a jQuery UI Slider in its place, acting as a proxy to the select element (regardless of whether it is still visible, or hidden from the user). This means you can use the jQuery Slider plugin alongside other input elements in a form and submit or serialize the form as if the slider is not even there. It also allows the user to interact and make a choice with or without javascript, since the select element can be used if the slider is unavailable.

The plugin enhances the jQuery UI slider in many ways, adding text labels and ticks on the slider axis, and tooltips that appear while a slider is being used. In this most recent update, we've also added ARIA support and a tabindex to the slider, allowing it to be accessible to users on assistive technologies, such as a screen reader. More info on that below.

Working Demo:

Demo Page

The demo above was generated from 2 HTML select elements with the following jQuery call:


$('select').selectToUISlider();

Now Updated for ARIA Support!

So what is ARIA Anyway?

WAI-ARIA, the Web Accessibility Initiative's Accessible Rich Internet Applications Suite, is a set of specifications for applying meaningful roles to web widgets, allowing them to be accessible to assistive technologies. You can find out more about ARIA here: WAI-ARIA Overview.

How we applied ARIA to the jQuery UI Slider

Following the guidelines for the slider role specified at WAI-ARIA Slider Role, this plugin now adds and manipulates the following attributes on each slider handle:

  • role(slider) The ARIA role for a slider widget.
  • aria-valuemin: The minimum value of the slider.
  • aria-valuemax: The maximum value of the slider.
  • aria-valuenow: The current value of the slider (automatically updates during slide).
  • aria-valuetext: The current human-friendly value of the slider (same as tooltip, and automatically updates during slide).
  • aria-labelledby: The ID of the label corresponding to the slider. We use the select element's corresponding label. The ID is generated if it's not in markup already.
  • tabindex: tabindex="0" is added to the slider handle, bringing it into the natural tab order of a form.
  • role of "application" to the slider's parent div: In our testing, this triggered our screenreader into the proper mode to meaningfully interact with the slider widget.

What we discovered along the way

A workaround for "aria-labelledby"

The ARIA spec provides the aria-labelledby attribute as a means of associating an ARIA widget with a label element on the page. By setting the value of the aria-labelledby attribute to the ID of a label, a screenreader should read that label's text aloud and associate the ARIA widget with its purpose.

While testing on Jaws and NVDA, we noticed that the aria-labelledby attribute was not being read aloud to the user as we expected. It seemed that while using "role=application" allowed the screenreader to recognize the markup as a slider widget, it also disabled the functionality of the aria-labelledby attribute. Unfortunately, we couldn't find a workaround, so we added a hidden span element inside each slider handle which acts in its place as a label for screenreader users. The text within the span reads "Slider control for" followed by the text contained in the form label on your page. In the case of the demo above, for instance, upon focusing on a slider handle, the screen reader will say "Slider control for Start Date", followed by instructions for using the control with keyboard commands.

To anyone who downloaded the earlier version of this plugin: The zip contains an update to the CSS file that hides this new span element visually, so be sure to update your code.

Avoiding duplicate controls for screenreader users

Now that this slider component is fairly accessible on its own, we found that, while it might be useful for a sighted user to see both the selects and the slider on the page and see them interacting with one another, it may lead to a confusing experience to screenreader users to have duplicate controls on the page that do the same thing. To work around this problem, we think it's best to hide the original select element from all users (screenreader users too) by styling it with display: none; once the slider has been generated. You can either hide the select by adding a class to it and creating a style in your CSS for it, or by simply adding a call to the .hide(); method to the end of your selectToUISlider(); call, as shown below:


$('select').selectToUISlider().hide();

The hidden select menu will still be able to store the value of the slider, so you can submit your form as if the slider was never there.

Don't want to hide the select element? If you can not hide the select element from the interface, perhaps you could provide some text for all users instructing that they can use either the select menu or the slider to accomplish the task at hand.

Using this plugin

To use this widget, you'll need to include jQuery version 1.3+, and the jQuery UI 1.7+ Slider plugin (which requires jQuery UI Core as well). You can get all of the necessary code through the zip provided below.

The following code example demonstrates the basic way to use this plugin:

HTML


<select name="speed" id="speed">
  <option value="Slower">Slower</option>
  <option value="Slow">Slow</option>
  <option value="Med" selected="selected">Med</option>
  <option value="Fast">Fast</option>
  <option value="Faster">Faster</option>
</select>

JavaScript


$('select').selectToUISlider();

The following demo shows the result of the code above:

Demo Page

Developer Options

The following options are available in this plugin:

  • labels: Number, number of labels to show. Labels are shown in even distribution from the center of the slider. Default is 3.
  • tooltip: Boolean, show tooltips or not. Default is true.
  • tooltipSrc: Specific String, tooltip text source from select menu. Available values are "value" or "text". Default is "text".
  • labelSrc: Specific String, scale label text source from select menu. Available values are "value" or "text". Default is "value".
  • sliderOptions: Object, accepts native jQuery UI slider options. Note:This plugin generates some of the native slider options. For the plugin to work as shown, do not override these options: step, min, max, range, slide, and values.

ThemeRoller-Ready

ThemeRoller-Ready Just like the jQuery UI slider widget, this plugin is ThemeRoller-ready, allowing it to be easily skinned to match your website's design. You can design and download a theme for this widget at ThemeRoller.com.

Download This Code

Version 2.0: FilamentGroup_selectToUISlider.zip

Your thoughts?

We'd love to hear what you think of this plugin and any suggestions you have for how it could be improved. These progressive enhancement features will eventually be rolled into the jQuery UI slider itself. You can track its progress at the jQuery UI Planning Wiki (Slider planning page), or better, post feedback or share your own ideas about the jQuery UI planning process by joining the development and planning wiki.

Book cover: Designing with Progressive Enhancement

Enjoy our blog? You'll love our book.

For info and pre-order: Visit the book site

Comments

This great plugin should be merged into jQuery UI slider as official feature.

Comment by Cloudream on 04/17  at  12:50 PM

I can think of dozens of great uses for this.  Very nice!

Comment by Nikola on 04/17  at  03:17 PM

There seems to be a slight bug when the final character of text is a “-”.  The minus character strangely drops down on the next line.

For example, just change “6am” to “6am-” in the example and you’ll see what I mean.

But still, A GREAT SCRIPT!

Comment by Burke on 04/17  at  05:21 PM

To clarify, I have only experienced this bug in IE7

Comment by Burke on 04/17  at  05:55 PM

@Cloudream: Thanks. I agree that this plugin is ready to move to UI. Let’s get the details into the planning wiki and get things moving!

@Nikola: Glad you like!

@Burke: Interesting, we will check into that issue. Thanks.

Comment by Scott (Filament) on 04/20  at  10:34 AM

Incredible! I would give my left arm for a demo of the date range slider coupled to an event list that updates dynamically based on slider input!
Great stuff! Thanks!

Comment by Adam on 04/21  at  12:24 PM

This is a great control!  Agree this really should really be merged with the standard JQuery slider.

However, one issue—not sure if its a bug or a feature grin—is that labels with a space or hyphen (-) are wrapping for me.  Any way to prevent that?  If there is no space or hyphen (e.g., if I change the space to an underscore), there is plenty of room to display the full label on one line.  Is wrapping the label a feature?

Comment by DFilip on 04/23  at  12:09 PM

Great plugin.
There is a little bug : when you change the html select, the handle is moved, but the tooltip is the same and there is no event trigger.

Comment by Ludovic on 04/30  at  04:45 AM

Great plug-in, but does anyone know how to affect the wrapping of labels, as well as the orientation of labels to tic marks?  I am still having troubles with the labels wrapping if there is a space in the label name, and something (?!) that I did is now getting the labels to align to the right of the tic marks, as opposed to center over the tic marks.

Comment by DFilip on 04/30  at  11:19 AM

This plugin is exactly what I needed! Only one important thing: is there a way to set a range with a fixed min value?

If there isn’t, any hints on how to achieve it? (I tried using two “select"s and setting first’s “option"s as “disabled”, but it didn’t work)

Thanks!

Comment by Xar on 05/04  at  03:24 AM

Hiya!

Really great plugin. The only thing I cant get working is the binding. I want to update a div with current range values as in http://jqueryui.com/demos/slider/#event-change.

I tried this:
$(’select#min_price, select#max_price’).bind(’slide’, function(event, ui) {
alert(’test’);
});

but that does not work.. any ideas?

Thanks a lot!

Comment by Tair on 05/06  at  01:13 PM

Holy hell. I had to click the “this post is outdated” link 5 times to get to this article. I mean, I’m glad you keep improving this thing but damn.

Comment by cwd on 05/08  at  12:50 PM

How would you create a default option which has no value, and does not show up on the slider? I mean, you can obviously set the default value to be a side, or one end, but what if you wanted to have the select return nothing unless the slider was moved or clicked? kinda like those radio boxes that you can’t uncheck after you choose one of them.

Comment by seady on 05/08  at  11:30 PM

@Tair: I managed to bind a function to the change event of the slider by modifying the sliderOptions variable:

$(’select#pFrom, select#pTo’).selectToUISlider({
labels: 10,
sliderOptions: {
change:function(e, ui) {
alert(’changed’+$(’select#pFrom option’).eq(ui.values[0]).text());
alert(’changed’+$(’select#pTo option’).eq(ui.values[1]).text());
}
}
});

The problem is you can’t bind a function to the slide event, as it will ruin the functionality of the slider (updating the original selects and the labels of the slider), but i think that the change event should suffice wink

Comment by Wiseon3 on 05/09  at  01:22 PM

We’ve updated the script with a quick bug fix for where the ARIA role="application" is applied. You can grab a copy of the zip above to get this update.
Thanks

Comment by Scott (Filament) on 05/11  at  04:56 PM

Hi guys!

Quick hello from Down-under… Thank you for publishing your work on the slider, it’s a really nice improvement from standard ui slider.
It did pick a small bug:

When using the select drop-box the tooltip is not updated although the slider moves to the correct position.
Need to add to the ‘selects.bind’ function the following:

selects.bind(’change keyup click’, function(){
[...]

// Update the tooltip
var textval = ttText(thisIndex);
thisHandle
.attr(’aria-valuetext’, textval)
.attr(’aria-valuenow’, thisIndex)
.find(’.ui-slider-tooltip’)
.text( textval );
});

Also I have written an alternative function (inputToUISlider) on that takes a select selector and an input selector. I use the select to decorate the slider (with scales etc) only and use the input selector as the controller: update value and also take in user input.
It works well although you could probably improve it. There is a couple of hacks in the script that i had to put in the end to get around errors.

Let me know if you’d want to look at it.
Cheers / Matt

Comment by Matt Lohier on 05/11  at  07:44 PM

Another bug (tested only in FF3) - if you put a negative date range in using the selectors (e.g. June 2008 - July 2007) the resulting slider is displayed incorrectly. Additionally, if you click on one of the two slider endpoints, it jumps to the same position as the other one.

Such invalid range cases surely need to be handled automatically by the slider widget rather than rely on implementing developers to add it each time?

Comment by Marcus Tucker on 05/12  at  11:37 AM

A few updates and bug fixes:
1. This plugin now has stylized arrows beneath the tooltips. The arrows are themeable to match the tooltip boxes. They use polygonal CSS, following the technique we described in this article: http://www.filamentgroup.com/lab/image_free_css_tooltip_pointers_a_use_for_polygonal_css/

2. We replaced a few $ variables with “jQuery” to prevent conflicts with other libraries.

3. The tooltips are now positioned from the bottom rather from the top, so tooltips with longer text will wrap neatly above the slider handles.

You’ll need to grab the latest ui.slider.extras.css and selectToUISlider.jQuery.js to see the updates.

Comment by Scott (Filament) on 05/13  at  12:27 PM

my question is similar to the one from seady: is there a way to have a default value that is not visible to the user and only active if he has not touched the slider? I’m asking because I’m developing online surveys and there it is handsome to have values for non-answered questions.

And another suggestion: expand the current script, so that - if options set accordingly - by default no marker is visible on the scale as long as the user hasn’t clicked on it. Would be a neat implementation of a VAS (visual analog scale): any preset marker would bias answers of the user and therefore it is essential to not have any marker on the scale prior to any user action.

Comment by marc on 05/14  at  07:30 AM

@Wiseon3

Thanks a lot! It worked smile

However, i still cant make the field to change with the slide. The change only updates it on mouse release..

Any ideas?

Btw, does anyone know how to get rid of sticking effect to the handles and make them not overlap but collide?

Cheers,

Tair.

Comment by Tair on 05/14  at  12:37 PM

First and foremost, great module.

Question: is there a special setup requirement with Select Slider with IE 7?

I have created a Drupal site that uses this module and it is fully functional using FireFox client.

I am having a problem with this module generated from my Drupal site within an IE 7 browser. It is throwing an error “Object doesn’t support this property or object” and it pertains to selectToUISlider. Code setup example:

if ( $(which) ) {
$(which).selectToUISlider();
}

However, with the same browser IE 7, I can access and use the demo slider on this page with no problems.

Ideas?

Thanks

Jeff in Seattle

Comment by Jeff Tanner on 05/14  at  05:08 PM

very nice tool. thx. great job.

Comment by projektowanie-stron-internetowych on 05/17  at  08:31 AM

Hi Scott, I made a change again, which I hope you’ll find interesting.
It has to do with the <optgroup> tags. I have an example with 1 date in 2006 (in optgroup with label 2006) and 5 dates in 2009 (in optgroup 2009).

Default behavior is to create to <dt>s both with 50% width.
I changed the width to
var widthPerc = (Math.min(100 - leftPerc, 100 * groups[h].options.length
/ (totalOptions-1))).toFixed(2);
such that it depends on the number of options in the optgroup.
(totalOptions is the total number of options in the select).

Furthermore, I removed the loop right after the comment “//style the dt’s”
because this only seemed to overwrite the values for ‘left’ again (I might
be wrong here...)

Greetings, Jonne.

Comment by Jonne on 05/19  at  09:42 AM

a solution for disabled option in select?

Comment by Thiago on 05/19  at  01:45 PM

congratulations for this job

Comment by Thiago on 05/19  at  01:48 PM

Hey Scott, GREAT work on the plugin! Can you also update the code to fix the “tooltip” bug when you change the slider based on the selectmenu? In that case, the tooltip is not updated.

I would also like to ask for a few enhancements;

0) I would like that the slider would fire a “sliding” event, so i can update instantly not waiting for the change event.

1) I added this CSS, since I want to control wether my label gets cut off or not.
.ui-slider span.ui-slider-label { white-space: nowrap; }

2) I added the tooltip fix suggested by “Matt Lohier on 05/11”

3) I would like to see the option that i can have my tooltip BELOW the slider. That way, it just looks nicer (horizontally) on forms when you have the slider. Ideally it would be great if you could make it so that you could choose the orientation of the tooltip (e.g. top/bottom on horizontal sliders and left/right on vertical sliders)

4) I would like to see the option that i can choose where i want to have the “optgroup” labels (e.g. top/bottom on horizontal sliders and left/right on vertical sliders). So in that case you would get: “Slider above -> Optgroup labels below -> Tooltip hovering over that” (or) Optgroup labels above -> slider -> Tooltip below something like that.

Comment by Gilles on 05/20  at  06:31 AM

p.s. on the current demo page, in the last demo, you can’t slide the “TO” part before the “FROM” part, which is good. But you can still use the “TO” selectbox to choose a date before the “from” part which screws up the slider.

Comment by Gilles on 05/20  at  06:38 AM

Hello, thank you for the script. Could you please let me know how can I style this part : http://www.grabup.com/uploads/22002213058F2009C21223166505.png . I would like to have custom image instead of default one.

Comment by Toni on 05/22  at  05:19 AM

This is great and I see many uses for it.

The only logical feature that it seemed to miss is once the end point dates are set, I was constantly grabbing the middle and trying to move the entire timeline left and right. This was logical to me.

Once I had set a range of 1 week or 1 month, there should be some Middle icon handle to move the entire range left or right while keeping the original range. Make sense?

Thanks,

Comment by Tri Bui on 05/23  at  01:30 AM

Great plugin, great design for the slider too.
It reminds me of the Google Analytics date range selector.

Comment by Maxime Perron Caissy on 05/24  at  07:03 PM

I’m testing it locally and had to deal with a scenario where a select list may or may not exist on a page.

In your example page, if you drop in
$(’select#doesnotexist’).selectToUISlider();
into the onload function, you’ll get a script error.

I fixed it by updating the script towards the bottom with the following to suppress output when the slider values are null.

if(values) {
if(isArray(values)){
jQuery(values).each(function(i){
sliderComponent.find(’.ui-slider-tooltip .ttContent’).eq(i).text( ttText(this) );
});
}
else {
sliderComponent.find(’.ui-slider-tooltip .ttContent’).eq(0).text( ttText(values) );
}
}

Comment by Dave Solomon on 05/26  at  11:09 AM

Would it be possible to allow the selection to be dragged, keeping the range size the same?

Nice though.

J.

Comment by John on 06/04  at  07:17 AM

Is there an easy way to switch the orientation? I need mine to be vertical.

Comment by Dale Larsen on 06/04  at  11:18 AM

I’d greatly appreciate support for pressing a Reset button. Right now if you do it the forms reset but the slider does not.

Comment by Doug S. on 06/04  at  07:16 PM

Oops.  Found a bug on line 174:

var style = (i == selectOptions.length-1 || i == 0) ? ‘style="display: none;”’ : ‘’ ;

This should be:

var style = (i == selectOptions.length-1 || i == 0) ? ‘ style="display: none;”’ : ‘’ ;

It’s a tiny difference, but it makes application/xhtml+xml documents go boom. :(

Comment by Illarane on 06/05  at  06:55 AM

PLEASE Could FilamentGroup start using Google Code (or similar) for all code/plugins/elements so that suggestions, revisions, bugs, etc can be more easily tracked/contributed by us all (and acted upon by FilamentGroup) rather than having to trawl through long comment threads like this, or keep an eye out for further revisions for this article?

Comment by Marcus Tucker on 06/05  at  07:01 AM

Great plugin!

I tried to use the tooltip update from select fix that was suggested by “Matt Lohier on 05/11”, but found that if a user clicked on the select box, the tooltip would lose the stylized arrow and no longer update from the slider. 

Has anyone else found this behavior?

Comment by Jason Vail on 06/28  at  09:57 AM

Wow, pretty impressive, im bookmarking this as i can see use for it in the near future.

Comment by John on 07/05  at  12:37 PM

Impressive control but the demo doesn’t seam to support keyboard shortcuts, e.g when the slider has focus and contains values Slow, Med & Fast pressing “M” should select “Med” in the same way a drop down list would.

Comment by Brian on 07/08  at  02:51 AM

I tried this in IE8 and at first it didnt display anything.  I refreshed the page and it suddenly appeared… Im not sure if this was a glitch with the script or just a strange IE8 bug?

Comment by the website guy on 07/10  at  01:23 AM

This is great and I still can’t believe no one else has done something like this. I’m extremely frustrated though - and I know it’s not your fault - because of the confusion of which scripts to use. There are so many iterations of different libraries* (jQuery 1.2.6, 1,3+ and jQuery UI 1.5+, 1.6+, 1.7+ and finally your own plug-in versions) it is hard to find the proper mix/match that works in situ.

Unfortunately for me, I am restricted to using jQuery 1.2.6 because of various outstanding bugs in 1.3+. This in turn means I must use jQuery UI 1.6. Yet your update to jQuery UI 1.5.3 links to a page that is described as for use with jQuery UI 1.6 but in actuality seems to skip 1.6 and instead states that it requires jQuery UI 1.7.1, which in turn requires jQuery 1.3+. *slaps forehead*

It is all very confusing and probably thanks to different authors updating their code bases at different times.

It would be nice if the Filament Group updated their pages to simply showcase one slider for each combo of jQuery/jQuery UI (i.e. 1.2.6/1.6 and 1.3.2/1.7.2). Although in the end I really do appreciate you guys spending the time sharing your work with us all.

*I’m not even going to mention the pre-jQuery UI library called interface. Oops, I just did.

Comment by skube on 07/15  at  02:11 PM

@skube: sorry, we agree it’s confusing trying to make sense of the matchups of jQuery and jQuery UI versions in the past months.
I’m pretty sure the script in this article is the one you’d need: http://www.filamentgroup.com/lab/progressive_enhancement_convert_select_box_to_accessible_jquery_ui_slider/

It runs on jQuery 1.2.6 and jQuery UI 1.5.3 (which was later bugfixed and released as 1.6).
Does this help?

Comment by Scott (Filament) on 07/15  at  02:30 PM

I’ve got an interesting issue where I’m updating the value of the select box programmatically, and then triggering the change event.  The change event is firing as it should, and the sliderOptions: { change: function() is firing as expected…

However neither the select box, nor the slider itself update to reflect the value change visually.  Has anyone else run into this?  The strangest part I think is that I can do the same code in firebug and it works exactly as you’d expect.  The .val(value) changes the select box, the .change event triggers my function and the update of the slider.

Comment by Alex on 07/15  at  04:16 PM

Great work, but in a page with multiple sliders, they are all atop each other in the correct location for the last one.. Is there a fix?

-Angus

Comment by Angus on 07/24  at  09:21 PM

Brilliant - great plug in!!

Comment by eggsy84 on 07/30  at  05:18 AM

Hi!
Is there a way to use this plugin without using an iframe ?

When i try, it overlays my text on bottom..?

Thanks for your answer, and thank you very much for this plugin wink

Comment by Nuranto on 08/06  at  10:52 AM

Small bug:

When having slider with tooltips, on click, tooltip appears, click somewhere on the page, tooltip dessapears, and thats ok. But when combined with select menu dropdown http://www.filamentgroup.com/lab/jquery_ui_selectmenu_an_aria_accessible_plugin_for_styling_a_html_select/, click on slider, tooltip appears, click on dropdown, tooltip stays visible, click somewhere on the page tooltip still stays visible! This should be fixed to hide tooltip whenever slider loose focus.

Comment by umpirsky on 08/15  at  03:24 AM

Incredible! I would give my left arm for a demo of the date range slider coupled to an event list that updates dynamically based on slider input!

Comment by توبيكات on 08/15  at  07:13 PM

I have this slider and selectmenu on my page, and suddenly it started to give me unresponsable script when firebug is enabled:

“A script on this page may be busy, or it may have stopped responding. You can stop the script now, open the script in the debugger, or let the script continue.

Script: file:///E:/dropbox/My%20Dropbox/Projects/auto-design/automobi.li/files/jquery-ui/js/jquery-1.3.2.min.js:12”

Any idea?

Comment by umpirsky on 08/20  at  09:03 AM

I have found that using the jquery-ui-1.7.1.custom.min conflicts with another jquery sortable that I have.  I’ve tried several different combinations and anytime the sortable is included, slider doesn’t slide. Has anyone else seen this?

Comment by chris on 08/20  at  02:46 PM

There seems to be a slight bug in Safari 4.0.2 under Mac OS X 10.5.7 Leopard.
The tool tip generates a horizontal scrollbar when in the extreme right.

Regards,

Comment by gabssnake on 08/20  at  08:51 PM

@ gabssnake: I believe that’s just because our demo pages in this article sit inside iframes. That problem won’t likely show up in an actual page.

Comment by Scott (Filament) on 08/21  at  08:43 AM

Plain awesome, just like your other articles. Thanks so much!

Comment by Blumen on 08/22  at  07:56 PM

If your zoomed in a bit and drag it all the way to the right you get a scrollbar appearing.

I’m not convinced about the dropdowns (although maybe you need them for accessability?)

Would be nice if instead of dropdowns, the dates were shown - light text on a dark background with rounded corners.

Comment by Stu on 08/24  at  05:23 AM

Thanks
i use it is script wink

Comment by Nurettin on 08/26  at  07:18 AM

Thanks for your work.

Is it possible to make it compatible with jQuery.noconflict() mode ?
Thanks for your help.

Comment by Mqrc on 08/26  at  10:38 AM

Sorry, yes it’s compatible, forgot to replace a “$” smile

Comment by Mqrc on 08/26  at  10:55 AM

Great - really useful!

Can you set the values under the slider to match the description rather than the value?

For example; if querying a database for a price range the currency value should $ or £ below but obviously is not required for the actual value passed to the database.

Comment by jamie on 08/28  at  08:38 AM

@Jamie: Glad you like it. I believe you’re looking for the labelSrc option. From there, you can choose whether the labels are pulled from the option’s value, or its text node.

Comment by Scott (Filament) on 08/28  at  08:48 AM

Guys, here’s a workaround for “messed up positioning on window resize” bug:

The problem is that the function that calculates position does not do so again once the menus have been created:
This is the basic flow:
1) intial creation of the menu object and event binding (very top of fg-meun.js)
2) menu object invokes ShowMenu() (top of the .js file)
3) showMenu() invokes create()
4) create() invokes setPosition() as its last action

so here’s the fragment, with the workaround:

this.showMenu = function(){ //around line 120 in my modified file

killAllMenus();
menu.create(); //NEW LINE
//if (!menu.menuExists) { menu.create() } //ORIGINAL LINE

//lots more stuff

}

Voila.  Now the menus are created on every click and the position is correct.  No it isn’t efficient, but I can detect virtually NO performace difference between the two versions at all.  Nothing else I tried, including trapping window resize event in the html script tag, and calling the setPosition function ealier in the create method, were working. 

It’s a badass menu by the way, and I can’t hold you guys responsible for the pathetic lack of Javscript speed by IE8!

Comment by Scott W on 08/31  at  01:33 PM

Great plugin.
There is a little bug : when you change the html select, the handle is moved, but the tooltip is the same and there is no event trigger smile

Comment by ديكورات on 09/05  at  09:56 PM

I have created a Drupal site that uses this module and it is fully functional using FireFox client.

Comment by منتديات on 09/05  at  09:59 PM

Great script..congratulations..i am using it right now

I have the same problems as @alex does when changing the values of comboboxes with [removed]

“However neither the select box, nor the slider itself update to reflect the value change visually...”

Comment by convertor valutar on 09/20  at  03:50 PM

@convertor valutar:

you can trigger the sliders to change using $(’#element’).click() after updating their selectedIndex via js.

Comment by curs on 09/21  at  02:05 PM

Great script you guys put together. I will be sure to implement this in everything i do.

P.S. It works great.!

Comment by hvac on 09/22  at  06:17 AM

if in a form I have several selectionelement, such as sel1,sel2,sel3....... I want to bind sel2, and sel3 with this tools, what should I do? Thanks

Comment by yang on 09/23  at  05:38 PM

This script is beyond amazing. It absolutely works great with other plug-ins and is easy to comprehend. Usually scrips are difficult and no one understands them. Great work.

Comment by Club Penguin on 09/24  at  12:37 PM

As i can see no one on this article had anything bad to say about this script. Just like me i absolutely love the script and wish to see more projects implemented by you guys.

Comment by Dental Computer on 09/24  at  02:36 PM

I really like this script, and I am just full of ideas on how to implement into my page. I’m so glad I stumbled across this entry! Excellent work.

Comment by George Susini on 09/24  at  11:25 PM

What is the license for this object?

Comment by Ducks on 09/28  at  10:16 AM

@Ducks This plugin is dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses. The js file in the zip has this notice, but we should probably add this to the articles too.

Comment by Todd (Filament) on 09/28  at  10:59 AM

How can I achieve to render separate slider tooltips for both selects? For me tooltip values are fetched from first select, so, no mather what is in 2nd select it always have labels that I put in 1st select.

Regards,
Saša Staenković.

Comment by umpirsky on 09/29  at  01:21 AM

This plugin is great, it really saved me a ton of time.  Is there any way to give it a fixed min range?

Comment by MLatzke on 09/30  at  01:50 PM

to disable slider:

$(function() {
$(’select#speed’).selectToUISlider({
labels: 5,
sliderOptions: {disabled:true}
});
});

Comment by Evgeniya on 10/02  at  06:16 AM

Great plugin, it worked extremely well for me. Gonna keep checking here for updates in the future!

Comment by Read Manga Online on 10/05  at  02:52 PM

I really needed to use the slide event. After a little expermentation I change the source to ‘return sliderComponent’ at the end, rather than returning this. I was then able to

$(’#select’).selectToUISlider().bind("slide", function(event,ui) {});

of course, the hide() can no longer be chained after the call, but

$(’#select’).hide().selectToUISlider().bind("slide", function(event,ui) {});

seems fine. Any reason not to do this?

Comment by PHW on 10/06  at  05:32 AM

Anyone who knows how to make two sliders take title from separate select element, not both to take from first one?

Comment by umpirsky on 10/06  at  06:03 AM

Jquery really has changed the way I go about working on the web.  It can pretty much accomplish anything flash can do and then some!

Thanks

Comment by affordable websites on 10/09  at  03:49 PM

Really thanks ! It’s really a very good work !

But… I can’t change my “select” to a “slider” when i click on a button or a link [url="#">. I have this error (firebug) :

==
second argument to Function.prototype.apply must be an array
+ Array.prototype.push.apply( this, elems ); --> jquery-1.3.2.js (ligne 146)
==

Here is the source of my HTML file :
...
<a id="TimelineTransform" ]click here[/url]
<div id="timeline">
<form>
<select name="Timeline" id="Timeline">
<option value="2004" selected="selected">2004</option>
<option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
</select>
</form>
</div>
...

And my script :
$(document).ready( function () {
$(’a#TimelineTransform’).click( function() {
$(’#Timeline’).selectToUISlider( {’tooltip’ : false} ).hide();
});
});

If you want you can replace :

$(’a#TimelineTransform’).click( function() {
$(’#Timeline’).selectToUISlider( {’tooltip’ : false} ).hide();
});

by

setTimeout( function() {
$(’#Timeline’).selectToUISlider( {’tooltip’ : false} ).hide();
}, 2000);

The result is the same : the select doesn’t dissapear and the error appear.

Really thanks for your help :’( !

Comment by Myrdhin on 10/13  at  08:59 AM

About my problem, we perhaps resolve it by replace the “selectToUISlider” source code, line 226 :

var values = sliderComponent.slider(’values’);

by :

var values;
if (sliderOptions.range) { values = sliderComponent.slider(’values’); }
else { values = sliderComponent.slider(’value’); }

It seems to work for me… Perhaps do you have a better idea ?
Thanks for your help.

Comment by Myrdhin on 10/13  at  09:26 AM

Good post Myrdihin. You are the MAN!!!

I can resolve my problem because you.

Comment by Tom on 10/18  at  02:30 PM

Excellent plugin..the best JS slider available!

One question..is there anyway I can restrict the user to scroll till some value only.. For example I have a slider with value 1 to 100 but the user will be able to move between 25 and 75 only.. other area is disabled with some light read color or something.. I tried making the options disabled="disabled" in the select. but still the slider can be used to select the values.

Comment by Anz on 10/19  at  01:32 AM

I’ve tried and tried.  I keep getting this error:

obj is undefined
selectToUISlider.jQuery.js (line 71)

Using
- jQuery 1.3.2
- UI 1.7.2 (with all components)

Could anyone make a suggestion?

Thanks!
-Dave

Comment by dyerrington on 10/21  at  11:03 PM

Hi
I am trying to capture the of the select box onChange event to use it without submitting the page but am unable to please suggest.

Comment by upendra on 10/23  at  06:45 AM

I’m having the same problem as Angus - multiple sliders on a page conflict with each other. Is there a way to fix this?

Comment by Murphy on 10/27  at  03:53 PM

Fortunately, I answered my own question: Conflicting ID’s on the selects were the culprit.

Awesome work guys.

Comment by Murphy on 10/27  at  04:13 PM

Angus, Murphy:

I’m not sure if this is the best way to do it, but here’s how I had multiple sliders on one page:

----------------------------------------------------------------------
var sliders = $(’select.slider’);

for (var i = 0; i < sliders.length; i++) {
$(’#’ + sliders.eq(i).attr(’id’)).selectToUISlider().hide();
}
----------------------------------------------------------------------

Each slider has it’s own unique ID.

Comment by MLatzke on 10/27  at  06:33 PM

Hi
I am trying to capture the of the select box onChange event to use it without submitting the page but am unable to please suggest.
for multiple sliders use this, have tested and working

var abc = $(’select#speed’).selectToUISlider().next();

var abd = $(’select#speed1’).selectToUISlider().next();

Comment by upendra on 10/28  at  04:37 AM

Nice stuf guys

Comment by moi on 10/29  at  04:23 AM

Anyone know how to get the slider to fire the select onChange event? Or how to get the new value of the select box without a form submit?
Thanks!

Comment by BassFace on 11/01  at  12:53 PM

that is really good blog thanks for info

Comment by Auto Club on 11/03  at  05:24 PM

hi,
congratulation for the great work.

how can i make the tooltip always visible? even in the beginin (when a select option is selected by default)?

thanks

Comment by gabro on 11/04  at  03:37 AM

jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript.

Comment by Biology Degree on 11/04  at  03:37 PM

hi,
how can i make the tooltip always visible even if a lose focus?

thanks

Comment by gabro on 11/05  at  05:32 AM

“We’ve updated our popular jQuery UI selectToUISlider plugin with ARIA support, making the jQuery UI slider widget more accessible to users on assistive devices.”

Thanks, I’m really glad you guys did this, as I’ve been trying to make my site more accessible.

Comment by black nightstands on 11/05  at  08:44 PM

How can we know when new version is released?

Comment by umpirsky on 11/06  at  01:55 AM

Where can I download plugin?

Comment by ecommerce website development on 11/06  at  08:00 AM

One question I have to restrict users to scroll up and some only .. like I have a slider with a value of 1 to 100, but users can move between 25 and 75 only .. other areas are clear with light colors. or read something .. I try to make the option disabled = “disabled” in the selection. but it can also scroll to select values.

Comment by proxy sites on 11/16  at  12:29 AM

how can change size of created slider???

Comment by pankaj on 11/16  at  04:20 AM

@pankaj CSS style of slider wrapper.

Comment by umpirsky on 11/16  at  04:27 AM

Excellent technique.  I love jquery more and more every day.

Comment by Las Vegas Escorts on 11/19  at  04:32 PM

Wow jquery really is incredible.  Thanks for sharing this tut.

Comment by digital luggage scale on 11/20  at  11:23 AM

Thank you , its useful

babak zawari
بابک زواری
بابك زواري

Comment by babak on 11/21  at  02:49 AM

I thank you for this informative article. I follow your vendors. It’s verry good.I wish you continued success

Comment by Adum on 11/23  at  03:40 PM

Thanks for your work. It works perfectly in IE8 plugin

Comment by australien on 11/29  at  12:17 PM

filamentgroup rocks...i love your script guys!

Comment by curs bnr on 11/29  at  01:06 PM

Hi ! Thx for the script, very good !
Is-it possible to fix some no-selectables values, to disabled some elements of a simple slider (no range) ?
Thanks a lot,
Manu

Comment by Manu T on 11/30  at  09:54 AM

thats is good post keep it up thanks for this smile

Comment by birthday sms on 11/30  at  12:34 PM

Nice script. Thank you very much.

Comment by WG Jena on 12/02  at  06:38 AM

Is there a way to avoid this from happening when the slider is close to right side of the page
or as in your example the frame

http://img187.imageshack.us/img187/8793/avoid.png

Comment by Daniel Langras on 12/09  at  12:50 PM

Deligated script but please give me the suggestion some times JQuery not executed on vista platform.

Comment by make affiliate program on 12/09  at  04:16 PM

How can i resolve the issue on Win32 in my JQuery scripts

Comment by network+ on 12/13  at  06:28 AM

All scripts are working but resolve this issue of Win pro.

Comment by a+ certification on 12/13  at  06:29 AM

How do you mean not execute on vista?

Comment by umpirsky on 12/13  at  08:15 AM

Hi,

I’m having the same issue as Dave:

obj is undefined
selectToUISlider.jQuery.js (line 71)
Using
- jQuery 1.3.2
- UI 1.7.2 (with all components)

Do I need to wait for you to release a new version?

Comment by Matt on 12/17  at  05:54 AM

I’ve solved my issue now, I was calling $(’select.slider’).selectToUISlider().hide() in my application js, which is called on every page.  On pages where there were no selects it was causing the js error in my previous comment.  The fix was:

$(’select.slider’).each(function() {
$(this).selectToUISlider().hide()
});

Comment by Matt on 12/17  at  07:11 AM

How can I make a slider for values 1$ to 100000$? I have to have 100000 < option > ? Is there other way to do this?

Comment by Michael on 12/17  at  01:18 PM

@Michael: in that case you’d probably want to start with an input element instead of a select. You could use the HTML5 input type="number" and provide a min and max attributes to use for generating your UI slider. We’ll post an article sometime in the near future with an example of this technique.

Comment by Scott (Filament) on 12/17  at  01:22 PM

Ok, but I have to modify selectToUISlider.jQuery.js file because its only support select element?

Comment by Michael on 12/17  at  01:52 PM

Hi, great slider! I didn’t see an answer to this in the comments-
-is there anyway to make it continuous instead of rewinding back to the start? so f.e. 1,2,3,4,1,2… instead of passing by 3,2,1 to go back to slide 1.
Thanks

Read more: http://www.dreamcss.com/2009/04/create-beautiful-jquery-sliders.html#ixzz0aQGGr6KX

Comment by TheWebLeap on 12/22  at  08:07 AM

Is there any way to modify the slider so you can grab it by the range bar (ui-slider-range) and slide both handles simultaneously?

Comment by Chris on 12/28  at  12:42 PM

Has there been an article released about how to make an “input type = number”? Like Michael, I need an slider for large range of values such as 1-10000 and making <option>s for all these is not an option :D

Any help is welcome!

@Michael: in that case you’d probably want to start with an input element instead of a select. You could use the HTML5 input type="number" and provide a min and max attributes to use for generating your UI slider. We’ll post an article sometime in the near future with an example of this technique.

Comment by Songe on 01/02  at  12:29 PM

@Songe: As soon as we can, we plan to post an article on this technique, yes.

Comment by Scott (Filament) on 01/02  at  12:58 PM

How do I change the slider programmatically?

I tried: $(myslider).selectToUISlider({ ‘sliderOptions’: { ‘values’: [’09:30’,’10:30’]}});

But that just creates an extra slider. Any ideas?

Comment by Hackeron on 01/03  at  09:12 PM

thaaaaaaaaaanks

Comment by منتديات on 01/04  at  11:00 PM

Hey Scott, beautiful work.  I noted a small shortcoming though and remedied it.

While it’s not 1/1000th as elegant as your solution to the problem would probably would be, I’ve been able to add another option to the .selectToUISlider options array (along w/ needed modifications to CSS), called “tooltipLocation”, allowing the user to specify the vertical orientation to the slider tooltip.

If you have a horizontal slider, placing the tooltip above the slider may not work w/ a given page.  The default configuration of my modified script display the tooltip above the slider, but {tooltipLocation: “below"} does all the lifting to change the placement.

While I’m sure you could code it in 10 seconds, if you’d like the modified code, please drop me a line.

Thanks for the awesome work…

Comment by Daniel on 01/07  at  02:00 PM

I have one SELECT element turning into a horizontal slider via selectToUISlider.

I know the instructions above warn to not override sliderOptions’ range, but I want the slider to have a different color on each side of the thumb (accomplished with either a range: “min” or range: “max”, if this were a plain ol’ jqueryui slider).

Looking at the code, it seems that range is set to true or false (depending on the quantity of sliders). So, I don’t think range: “min” would break anything for one SELECT element.

Setting range: “min” renders the expected DIV class="ui-slider-range ui-slider-range-min ui-widget-header”, but the width does not change (from 0).

I cannot get the desired behavior, any suggestions?

I also tried using JS to build a second fake SELECT element and rendering the pair via selectToUISlider to create the range, but then I could not figure out how to disable the “fake” thumb so only the real thumb would accept events (and I can’t help but feel that approach is a little convoluted).

Comment by Adam Hutton on 01/15  at  12:25 PM

@Adam: Interesting problem. I gave it a little investigation and couldn’t immediately see why the range: min doesn’t seem to work as expected. It may have to do with the handle we’re generating before creating the slider. An improved implementation would create the slider first, then find the anchor inside it to apply ARIA.
We may have some time later this week to take a look. Let us know if you figure out the conflict. Thanks!

Comment by Scott (Filament) on 01/17  at  09:14 AM

Very simple and useful thank you.

Comment by Campervan Hire Australia on 01/18  at  11:56 PM

@Scott: I think I’ve made some progress. The jQuery UI slider() can take value:int or values:array, but range:"min" only works with value:int.

$(’#someDiv’).slider({range:"min", min:0, max:10, value:3}) works.
$(’#someDiv’).slider({range:"min", min:0, max:10, values:[3]}) does not work.

At this point, I would consider that a bug in jQuery UI, but it can be accounted for without too much work (I hope) in selectToUISlider.

Comment by Adam Hutton on 01/19  at  03:41 PM

Nice. I was waiting a few months for them to start supporting it fully. Great news!

Comment by Sweet irena on 01/22  at  04:45 PM

If using this with a framework that needs dots in the id for naming the objects, this will not work because it will not escape the dot. So I changed the source to these:
tempArr.push(’handle_’+jQuery(this).attr(’id’).replace(".", “\\."));
var thisHandle = jQuery(’#handle_’+ jQuery(this).attr(’id’).replace(".", “\\."));

and it works now.

Comment by Alex on 01/26  at  09:33 AM

Thats really very good work, thank you for sharing! Simple but very usefull…

Comment by Bilderdienste on 01/26  at  04:43 PM

Is there a way to hide the dropdownlist and only display the slider?

Comment by dotnetster on 01/27  at  04:22 PM

Nice and easy… they have a little gray block of code above that shows how:

$(’select’).selectToUISlider().hide();

Just put the .hide() after the selectToUISlider call and you’re done!

Comment by Daniel on 01/27  at  04:39 PM

How do u include it inside jquery tabs ?

i m trying to include it in a ajax loaded tab and its not working.

it works in its own but not inside the tabs.

any idea how to fix this ?

thanks

Comment by ihab on 01/30  at  01:24 PM

Looks like change handler is triggered multiple time during the slide, before releasing mouse button. On click it’s triggered twice.

That was not the case before jQuery UI 1.8.

Code:
$("#year, #year2").selectToUISlider({"sliderOptions”:{"change”:myfunc},"labels":5});

Anyone?

Comment by umpirsky on 02/02  at  10:00 AM

Here’s my question/situation:

I am using this to place sliders on a questionnaire. The people running the questionnaire want the labels to appear a specific way. They want the value to appear as part of the label, but ABOVE the label text.

For example, if the value is 7 and the label text is STRONG, they want the number 7 to appear above the word STRONG, just as if it were coded 7
STRONG.

Is there any way to do this?

Comment by Patrick Moore on 02/02  at  10:20 AM

Nice stuf guys, filament group rocks!

Comment by Blumen bestellen on 02/03  at  03:20 PM

I have added

onchange = “this.form.submit();”

to the select tag in the HTML. It works great whenever I use the dropdown to change my selection but it is not recognized when I use the slider, even though the dropdown changes as I slide. Any ideas how to make it autosubmit after I edit the slider?

Comment by Sam on 02/11  at  12:06 PM

Hello and thx for this nice plugin. I made a simple patch for putting a simple class on the handlers so can distinguish the left from the right or whether it is a single one. Are you interested in getting it? How can I send it to you (a “social coding” site would be nice, as for example google code, github, etc....)

Comment by Nikos Dimitrakopoulos on 02/12  at  03:05 AM

Is there any way I can make the tooltip visible as default? I want it to show up as soon as the slider is loaded and not disappear once my mouse unfocuses.
I’ve spent the better half of this morning and two cups of coffee trying to find it but haven’t had any luck!!!

Also still need help with the onchange function.

Have a BEAUTIFUL implementation of this code I’d be happy to share with the developers once I’m 100% running. Donations will rain!!

Comment by Sam on 02/12  at  10:44 AM

Anyone having problem using this with JQuery 1.4.1 and JQueryUI 1.7 or do I have to use UI 1.8 with 1.4?

Thanks!

Comment by Chris on 02/13  at  12:13 PM

@ Chris I use UI 1.8 with 1.4.

Comment by umpirsky on 02/14  at  05:05 AM

That doesnt work for me?  Getting contructor is null or not an object in the isArray function?  Using IE8

Comment by Chris on 02/15  at  08:30 AM

I really like how you guys put this slider together! I’m still having some trouble playing around with tweaking some of the visual layout of the slider, but overall, it’s really nicely done.  Thanks Filament team; will be looking forward to updates.

Comment by NV Web Design on 02/16  at  04:01 PM

Hi, Can anyone tell me how to use ARIA support ? and what if i don’t want to use select control to populate the slider?

Comment by ntimesc on 02/19  at  02:15 AM

Is it possible to give each select option a different background color on the slider? If yes, How can I do that?

Comment by Gerben van Erkelens on 02/23  at  07:03 AM

I also like the feature to show the tooltip all the time.

Comment by Gerben van Erkelens on 02/23  at  09:41 AM

Can someone explain how I can show the tooltip on initial rendering of the slider control?  Say the default value is 5 on a scale of 1 to 10.  I can get the slider handle to default to 5 but I would like to show the tooltip at 5.  Thanks.  Keep up the good work.

Comment by dotnetster on 03/01  at  08:57 AM

@sam @Gerben I changed display: none; to display: block; in the ui.slider.extras.css to show tooltips always

@sam any luck to show toolip onload/render of slider?

Comment by dotnetster on 03/01  at  10:13 AM

Hello,

I’ve just upgraded to jQuery 1.4 and JQ UI 1.8rc3 and this seems to have broken an accessible slider I’m using.  Do I need to change anything to get this to work?  Anyone else having problems/success?

Thanks!

Comment by Rick on 03/02  at  10:12 AM

@dotnetster
which display: none did you change? There are a lot of them in that CSS file.

Comment by Gerben van Erkelens on 03/02  at  10:23 AM

@Gerben

for any class using ui-slider-tooltip

Comment by dotnetster on 03/02  at  12:13 PM

@dotnetster I tried the display:block but the tooltip still does not appear as soon as the slider is loaded.

Also, I’ve had no luck getting the onchange event to fire.

Comment by sam on 03/02  at  12:18 PM

@dotnetster
I’m getting the tooltip now, but it stand below of the sliderbar instead of above. And the layout of the tooltip is entirely different

Comment by Gerben van Erkelens on 03/02  at  01:28 PM

Nice plugin! it saved me a lot of trouble when I needed slider with zend_form.

Comment by dr Casper Black on 03/05  at  05:18 PM

@Casper I use if with Zend_Form too, extended ZendX_JQuery_Form_Element_UiWidget wink

Comment by umpirsky on 03/06  at  03:30 AM

I’m using 4 range selectors and it is taking the page around 5 seconds to render the js in IE(7&8;). Is this expected from this plugin or is there something I should be looking for to correct this?

Comment by Matt on 03/17  at  10:37 AM

Add a Comment:* required fields

Book cover: Designing with Progressive Enhancement

Enjoy our blog? You'll love our book.

For info and pre-order: Visit the book site

Recently on Twitter...

updated Visualize jQuery accessible Canvas charts w/ new design & ARIA (from book Designing w/ Progressive Enhancement) http://bit.ly/dsxdtV

@filamentgroup 3 days ago...