Selects

Required plugin

This feature requires the plugin files js/developr.input.js and css/styles/form.css

The template form plugin provides a replacement style for selects, for a uniform styling accross browsers and platforms. To use it, just add the class select to any select element:

<select class="select">
	...
</select>

Select are focusable, and work with keyboard shortcuts too: up and down arrows to navigate in the values list, enter to select, type any text to scroll to the first matching value. On touch devices, the default UI is used (unless it is disabled with an option - see reference below for more details)

As most form elements, selects can be disabled, either by disabling the original select or by adding the class disabled.

// Disabled
<select class="select" disabled>
	...
</select>

// Looks like disabled
<select class="select disabled">
	...
</select>

Note that if you need to disable/enabled selects at runtime, you must use the template methods:

// Enable select
$(selector).enableInput();

// Disable select
$(selector).disableInput();
Search feature

Since v1.3, the select can embed a serach field that display over the selected value when the select opens. By default, it is automatically used if the select has more than 40 values, and you can control when to show it using the following options: searchField, searchIfMoreThan and searchText (see reference below for more details).

Dynamic changes

If you change the value of the select with javascript, you need to tell the styling plugin that it has changed: just fire a change event:

$(selector).change();

And if you change the option's list, trigger the corresponding special event to force a refresh:

$(selector).trigger('update-select-list');

Both events can be chained if both options list and value have changed:

$(selector).trigger('update-select-list').change();

Option classes

Colors

As any other element, selects can use the 9 color sets:

Open on hover

By default, selects open when the user clicks the down arrow, but they may also open on hover: just add the class auto-open.

<select class="select auto-open">
	...
</select>
Expandable list

On the default select style, the list has the same width as the whole select, but if you want the list to expand (for long texts) add the class expandable-list.

<select class="select expandable-list" style="width:100px">
	...
</select>

Setting a width prevents the original select from streching to match the longest value.

Check list

This is an alternative style, great for short lists, and it is more touch-friendly:

<select class="select check-list">
	...
</select>

Multiple selects

Default style

Multiple selects look like this:

<select class="select" multiple>
	...
</select>

Check-list style:

<select class="select check-list" multiple>
	...
</select>

You may control the number of visible elements using the size attribute.

Easy multiple selection

Multiple selects work like standard multiple selects, holding Ctrl or Cmd to select several values. To make it easier for users to select multiple values, add the class easy-multiple-selection, and the selection can be done only by clicking (note that this is the default behavior on touch devices)

<select class="select easy-multiple-selection check-list" multiple>
	...
</select>

By default, easy multiple selection does not allow to un-select all values, but this may be enabled using the class allow-empty

<select class="select easy-multiple-selection allow-empty check-list" multiple>
	...
</select>
Force styles

It is possible to display a multiple select as a drop-down using the classmultiple-as-single, here with some of the above options:

<select class="select multiple-as-single easy-multiple-selection check-list" multiple>
	...
</select>

On the oposite, single-value selects can be displayed as multiple using the class multiple (but still allow only one value)

<select class="select multiple check-list">
	...
</select>

Using the style only

It is possible to use the drop-down style without any underlying select element: just build the corresponding markup, and the plugin will handle it as well:

<span class="select" tabindex="0">
	<a href="#" class="select-value">Edit</a>
	<span class="select-arrow"></span>
	<span class="drop-down">
		<a href="#">Option 1</a>
		<a href="#">Option 2</a>
		<a href="#">Option 3</a>
		<a href="#">Option 4</a>
	</span>
</span>

The tabindex attribute is used to make the element focusable

Note that most styling options will work as well.

Options reference

The defaults may be modified at runtime in $.fn.styleSelect.defaults, and options may be passed inline using the data-select-options attribute

styledList
False to use system's drop-down UI, true to use style's drop-downs
Type: boolean|null
Default: true
styledOnTouch
For touch devices: false to use system's drop-down UI, true to use style's drop-downs, or null to guess (true for check-list style, false for others)
Note: only works if styledList is true
Type: boolean|null
Default: null
openOnKeyDown
When focused, should the arrow down key open the drop-down or just scroll values?
Type: boolean
Default: true
noValueText
Text for multiple select with no value selected
Type: string
Default: ''
singleValueText
Text for multiple select with one value selected, or false to just display the selected value
Type: string|boolean
Default: false
multipleValuesText
Text for multiple select with multiple values selected, or false to just display the selected list
Tip: use %d as a placeholder for the number of values
Type: string|boolean
Default: '%d selected'
allValuesText
Text for multiple select with all values selected, or false to just display the selected list
Tip: use %d as a placeholder for the number of values
Type: string|boolean
Default: 'All'
searchField
Enable search field when open - use null to automatically use when list has more than searchIfMoreThan elements
Type: boolean|null
Default: null
searchIfMoreThan
Minimum number of elements to trigger a search field, if searchField is null
Type: int
Default: 40
searchText
Helper text for seach field
Type: string
Default: 'Search'