My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
jQueryStyledSelectOverview  
Project Overview
Project-jQuery-styledSelect
Updated Mar 24, 2009 by liep...@gmail.com

Overview of the styledSelect jQuery plugin

The styledSelect plugin for jQuery lets you replace <select> form elements with freely stylable markup.

The original select element stays in the page so your form won't change and users without Javascript simply fall back to the original form element.

Unlike other implementations styledSelect directly replaces a select element. As such it does not support arbitrary data for each element, just the value and text of an option tag.

Download the latest version here

The download contains regular and minified versions as well as the examples.

Homepage at plugins.jquery.com

Examples

Usage

Simplest case (usually sufficient):

$('select').styledSelect();

The styledSelect() method can take a single parameter, which should consist of a list containing options that you want to override. These are the available options with their default values:

{	
	selectClass: 'styledSelect',
	openSelectClass: 'open',
	optionClass: 'option',
	selectedOptionClass: 'selected',
	closedOptionClass: 'closed',
	firstOptionClass: 'first',
	lastOptionClass: 'last',
	zIndexApply: false,
	zIndexStart: 250,
	deactiveOnBackgroundClick: true
}

Most options deal with the classes added to the markup. Look at the Markup section below to see where they go. When zIndexApply is set to true, the div, ul and li elements each get their own z-index. li gets the highest, equal to zIndexStart. ul gets one less, div gets two less. This is for the first select element that was matched by the selector on which styledSelect(). The following select element gets lower z-indexes, starting at zIndexStart-3.

The option deactiveOnBackgroundClick was added in version 1.1. When true, clicks into any other element but the currently open select element result in the select closing.

Markup

styledSelect inserts a bit of HTML next to the select element. The full list of select options is created each time the user clicks on the select box. This ensures that the "fake" select is always in sync with the actual select element.

Closed select:

<div class="styledSelect">
	<ul>
		<li rel="value" class="closed">Title</li>
	</ul>
</div>

Open:

<div class="styledSelect open">
	<ul>
		<li rel="value1" class="option first">Title 1</li>
		<li rel="value2" class="option selected">Title 2</li>
		<li rel="value3" class="option">Title 3</li>
		<li rel="value4" class="option last">Title 4</li>
	</ul>
</div>

Usability

Please be aware of the usability issues that arise from using this plugin instead of just displaying the system-styled selects. it is established that users respond better to known elements. They already know how select boxes look on their system, they'll find it easier to use if it doesn't look totally different. Also keyboard control is impossible. You can't tab through a form and focus on a styledSelect box. Once opened, arrow keys can't be used to select a value.

If you absolutely have to have nicely styled select boxes this is for you. Otherwise please think twice.

Plans

  • Scrolling content - right now these styled selects really arent't feasible for a larger number of options.
  • Support for multiline selects
  • More intelligent selector - currently selects must be targeted directly. styledSelect should also automatically target selects inside the current selector
  • Customizable HTML
  • Close select when targetting other form element
  • Close select when leaving its vincinity for a number of seconds

[http://code.google.com/p/lnet/w/list?q=Project-jQuery-styledSelect Wiki | Issues | Downloads ]

Comment by realax...@gmail.com, Oct 22, 2009

Need to add some functionality to design different options. For example, I need create list of languages which containing options illustrated with national flags. Or I need create list of sorting orders (ascending, decreasing) in the icon driven manner.

Comment by aaronwin...@gmail.com, Mar 17, 2010

This apparently does not trigger the jquery 'changed' event for the selector when changing a value. Is there a way to ensure this behavior, or to at least add a 'changed' event to this plugin?

Comment by aaronwin...@gmail.com, Mar 17, 2010

OK, to fix the 'changed' event handling, you need to apply the fix in http://code.google.com/p/lnet/issues/detail?id=41

Comment by igorgu...@gmail.com, Sep 12, 2011

addons for "language-box support":

move current selected in the top the list: jQuery('ul li.selected:not(:first-child)', cs).insertBefore(jQuery('ul li:first-child', cs));

using 'id' instead of 'rel' allows to show country flag as background of li

Comment by finnem...@gmail.com, Oct 5, 2011

The performance on large number of selects is not very good. A significant speed up (several hundred ms per select box on my machine) seemed to be possible by doing:

s.hide().after(cs)

instead of

s.hide(0).after(cs)

The jquery code that slows it down is probably this bit from the hide-function:

if ( speed || speed === 0 ) {
  return this.animate( genFx("hide", 3), speed, easing, callback);

if the speed parameter is not set, no animation is attempted - ie the raw css-display-property is set to none.

Comment by Devin...@gmail.com, Nov 15, 2011

I ran into an issue where when the form element is hidden, say in a popup or hidden area on the site the line:

s.hide(0).after(cs)

does not properly hide original select list, and results in having the original non styled and styled lists present at the same time.

I ended up making the call to hide select boxes when the popups are displayed. Not sure if something can be altered to make this work with hidden display areas.


Sign in to add a comment
Powered by Google Project Hosting