groenroos / minimalect

Minimal select replacement for jQuery
350 stars 52 forks source link

minimalect

Minimal select replacement for jQuery by @groenroos. For usage examples, visit groenroos.github.io/minimalect

New in 0.9.0 (28th May 2014)

Usage

Include jquery.minimalect.min.js after you load jQuery (1.7 or newer). Then simply do;

$("select").minimalect();

Remember to also include the stylesheet (SCSS and minified CSS available);

<link rel="stylesheet" type="text/css" href="https://github.com/groenroos/minimalect/blob/master/minimalect.min.css" media="screen" />

The default style is very understated, so it's easy to modify to better suit your needs. By default, no graphics are used; the arrow symbols are Unicode characters. Please be advised that not all typefaces on all devices support this, and depending on your target device, you may want to replace it with pre-rendered graphics.

AJAX functionality

You can also use Minimalect as a way to display search results from an AJAX call. For this, pass the ajax setting with the URL to the backend. Minimalect will send a POST request with the key q containing the value of the user's search. Minimalect will expect a JSON response with an array of objects, each having two keys: name and value.

Note, that the response received from the AJAX service will also modify choices available in the original select element, so that the selected choice may be appropriately sent with the rest of the form. The original contents of the select element are not restored if the user doesn't pick anything.

Programmatically changing the selected choice

If you wish to change the current value of the select, you can simply make your changes to the original element like you would normally with .val(). Minimalect will take it from there, providing that the live setting is set to true, like it is by default.

Programmatically changing the available choices

Since version 0.9.0, Minimalect will automatically recognize if the original options are changed dynamically, and the changes are reflected in the user-facing element. For this, Minimalect uses the MutationObserver, which has spotty cross-browser support. For support in IE10 and earlier, Firefox 13 and earlier, Chrome 26 and earlier and Safari 5.1 and earlier, either use a polyfill, or call the update method manually.

Available methods

You can call various Minimalect methods to control it programmatically. You can call methods by passing the method name as a string in a second call, e.g. .minimalect("method")

Available options

You can pass an object as a parameter for the .minimalect() call, to override the default settings.

You may edit all the CSS classnames that Minimalect uses so that they don't collide with ones you already use, as well as the user-facing messages for customization or internationalization.

Settings
Messages
Classes
Callbacks

Bugs & Support

Developed by @groenroos. Please list all bugs and feature requests in the Github issue tracker.

Licensed under the MIT license.