Fork me on GitHub

It depends on jQuery 1.4.2 and jQuery UI 1.8. The widget is styleable using Themeroller. It works in an unobtrusive fashion, by just turning html multiple select inputs into a sexier equivalent. There's no extra markup needed.

Localisation support is done through the localization plugin available here.

The widget is available under the dual MIT and GPL licenses.


Demo

Multiselect with local content :
Test submit (will not reload the page)
Multiselect with remote content :
Test submit (will not reload the page)
Toggle external controls (IE6 doesn't render well this layout.... and I don't care)
Controls :
Enable multiselect :
Get selected values :
Select values :

Manual selection :
(Match option values, not text)
Search :

Features

Localisation

Known bugs

Limitations

Todos...

Here's a list of features that may or may not be implemented in future releases (no specific versions).

Contributors

Misc

There are no limitations. Do whatever you want with this plugin. If you did some nice modifications, just let us know (via Github). We'd be happy to review them, and perhaps include them.

  • animated

    Type:
    String, null
    Default:
    'fast'

    When animated is specified, the multiselect UI will use transition effects between interactions. The possible values are 'fast', 'slow' and null (no animation).

    Code examples

    Initialize a multiselect with the animated option specified.
    $('.selector').multiselect({ animated: 'fast' });
    Get or set the animated option, after init.
    //getter
    var animated = $('.selector').dialog('option', 'animated');
    //setter
    $('.selector').dialog('option', 'animated', 'slow');
  • dataParser

    Type:
    Function
    Default:
    defaultDataParser

    Used with remote search, this function is called to parse the data received and return the data in the expected format.

    The function takes the raw received data from the request and should return a JSON object corresponding to the new available options to add. The returned object should have the following structure :

    {
    	"key1": {
    		selected: boolean,
    		value: string
    	}[,
    	"key2": {
    		selected: boolean,
    		value: string
    	}[,
    	...]]
    }

    If the data should be discarded, the function may return false or null.

    Code examples

    Initialize a multiselect with the a pass-through dataParser
    (expects to receive the correct raw data format from the server)
    $('.selector').multiselect({ dataParser: function(data) { return data; } });
    Get or set the dataParser option, after init.
    //getter
    var dataParser = $('.selector').dialog('option', 'dataParser');
    //setter
    $('.selector').dialog('option', 'dataParser', newDataParser);
  • dividerLocation

    Type:
    float
    Default:
    0.6

    Specify the portion of the selected (left side) area of the multiselect. To have an even split multiselect, set dividerLocation to 0.5. The value should be between 0 and 1.

    Code examples

    Initialize a multiselect with the dividerLocation option specified.
    $('.selector').multiselect({ dividerLocation: 0.55 });
    Get or set the dividerLocation option, after init.
    //getter
    var dividerLocation = $('.selector').dialog('option', 'dividerLocation');
    //setter
    $('.selector').dialog('option', 'dividerLocation', 0.55);
  • droppable

    Type:
    String
    Default:
    'both'

    Enable or disable basic drag and drop functionality between the selected list (left) and the available list (right). The possible values are 'both', 'left', 'right', 'none'. And set drop support in both lists, the selected list, the available list, or no drag and drop respectively.

    This setting is readonly at run-time. Trying to set this property after initialization will trigger a messages event.

    Code examples

    Initialize a multiselect with the no drag and drop functionality.
    $('.selector').multiselect({ droppable: 'none' });
    Get the droppable option, after init.
    //getter
    var droppable = $('.selector').dialog('option', 'droppable');
  • hide

    Type:
    String
    Default:
    'slideUp'

    Specify the hide animation function to use. If animated is null, the value will be overriden to 'hide'. The possible values are any available function effects name. The default value for animated hide effect is 'slideUp'.

    Code examples

    Initialize a multiselect with the hide option specified.
    $('.selector').multiselect({ hide: 'fadeOut' });
    Get or set the hide option, after init.
    //getter
    var hide = $('.selector').dialog('option', 'hide');
    //setter
    $('.selector').dialog('option', 'hide', 'fadeOut');
  • nodeComparator

    Type:
    Function, null
    Default:
    defaultNodeComparator

    Comparator function used in ordering the list's elements during transfer. The function takes two arguments, a and b, and should return a numeric value less than 0 if a < b, 0 if a == b, or greater than 0 if a > b respectively.

    The function is only called when the list is not sortable. By default, items are sorted by content value ascending. To completely disable automatic list ordering, set nodeComparator to null.

    Code examples

    Initialize a multiselect with option key ordering nodeComparator.
    $('.selector').multiselect({ nodeComparator: function(a, b) {
    	var ka = node1.data('multiselect.optionLink').val(),
    	    kb = node2.data('multiselect.optionLink').val();
    	return ka == kb ? 0 : (ka < kb ? -1 : 1);
    } } });
    Get or set the nodeComparator option, after init.
    //getter
    var nodeComparator = $('.selector').dialog('option', 'nodeComparator');
    //setter (will only be applied on new inserted items only!)
    $('.selector').dialog('option', 'nodeComparator', newNodeComparator);
  • nodeInserted

    Type:
    Function, null
    Default:
    null

    Callback function fired for each newly inserted items. The function takes the inserted item as a JQuery object and does not expect any return value.

    Internally, items are cached as a best effort basis, therefore some items may be inserted, removed and re-inserted during manipulations.

    Code examples

    Initialize a multiselect a nodeInserted callback.
    $('.selector').multiselect({ nodeInserted: function(item) {
    	item.attr('title', item.text()); // set a "tooltip" to newly added items
    } } });
    Get or set the animated option, after init.
    //getter
    var nodeInserted = $('.selector').dialog('option', 'nodeInserted');
    //setter
    $('.selector').dialog('option', 'nodeInserted', newCallback);
  • searchable

    Type:
    boolean
    Default:
    true

    Enable or disable search capabilities for this instance of the multiselect.

    Code examples

    Initialize a multiselect with searchable option disabled.
    $('.selector').multiselect({ searchable: false });
    Get or set the searchable option, after init.
    //getter
    var searchable = $('.selector').dialog('option', 'searchable');
    //setter (reset search filter)
    $('.selector').dialog('option', 'searchable', false);
  • searchDelay

    Type:
    int
    Default:
    400

    Define the input search delay before a request is sent to the server. The default value is 400 milliseconds.

    Code examples

    Initialize a multiselect with a 1 second searchDelay.
    $('.selector').multiselect({ searchDelay: 1000 });
    Get or set the searchDelay option, after init.
    //getter
    var searchDelay = $('.selector').dialog('option', 'searchDelay');
    //setter
    $('.selector').dialog('option', 'searchDelay', 1000);
  • show

    Type:
    String
    Default:
    'slideDown'

    Specify the show animation function to use. If animated is null, the value will be overriden to 'show'. The possible values are any available function effects name. The default value for animated hide effect is 'slideDown'.

    Code examples

    Initialize a multiselect with the show option specified.
    $('.selector').multiselect({ show: 'fadeIn' });
    Get or set the show option, after init.
    //getter
    var show = $('.selector').dialog('option', 'show');
    //setter
    $('.selector').dialog('option', 'show', 'fadeIn');
  • sortable

    Type:
    String
    Default:
    'left'

    Enable or disable item sortable functionality through drag and drop for the selected list (left) and/or the available list (right). The possible values are 'both', 'left', 'right', 'none'. And set sortable support in both lists, the selected list only, the available list only, or none sortable respectively.

    This setting overrides droppable for the specified list. This setting is readonly at run-time (like droppable).

    Code examples

    Initialize a multiselect sortable functionality across both lists.
    $('.selector').multiselect({ sortable: 'both' });
    Get the sortable option, after init.
    //getter
    var sortable = $('.selector').dialog('option', 'sortable');
  • remoteParams

    Type:
    Object
    Default:
    { }

    Specify some extra remote parameters to send with every remote search requests. Note that the 'q' argument is reserved by multiselect and if remoteParams contains a key called 'q', it will be overriden with the search query.

    Code examples

    Initialize a multiselect searchable remotely with extra params
    // server expect to receive a public key for secure requests
    // our public key is "foo", send this key automatically with every search request
    $('.selector').multiselect({ remoteUrl: 'ajax.php', remoteParams: { publickey: 'foo' } });
    Get or set the remoteParams option, after init.
    //getter
    var remoteParams = $('.selector').dialog('option', 'remoteParams');
    //setter
    $('.selector').dialog('option', 'remoteParams', { publickey: 'bar' });
  • remoteUrl

    Type:
    String, null
    Default:
    null

    If the multiselect is searchable, then setting this option will allow fetching new data from a remote script. The returned data may vary if a custom dataParser is set.

    The default parser expects to receive the data as plain text, one option per line, in the format of :

    value=text

    Code examples

    Initialize a multiselect with a given remote url.
    $('.selector').multiselect({ remoteUrl: 'ajax.php' });
    Get or set the remoteUrl option, after init.
    //getter
    var remoteUrl = $('.selector').dialog('option', 'remoteUrl');
    //setter
    $('.selector').dialog('option', 'remoteUrl', '/path/to/script.php');
  • enabled

    Signature:
    .multiselect( 'enabled', [state], [msg] )

    Get or set the state of the enabled multiselect. If no state is specified, will act as a getter. If state is set to false, the msg argument will display the specified string as custom disabled message inside the multiseelct.

  • deselect

    Signature:
    .multiselect( 'deselect', item )

    Deselect the specified item. The value should be the text of the option to verify (not case sensitive).

    If only the option key is known, the option may be specified using the following command:

    $('.mulstiselect').multiselect('deselect', $('.multiselect').find('option[value=key]').text() );
  • destroy

    Signature:
    .multiselect( 'destroy' )

    Remove the multiselect functionality completely. This will return the element back to it's default look.

  • isBusy

    Signature:
    .multiselect( 'isBusy' )

    Return the busy state of the multiselect. The method will return true if the multiselect is processing item selection, search, etc.

  • isSelected

    Signature:
    .multiselect( 'isSelected', item )

    Return true if and only if item is selected. The value should be the text of the option to verify (not case sensitive).

    If only the option key is known, the option may be specified using the following command:

    $('.mulstiselect').multiselect('isSelected', $('.multiselect').find('option[value=key]').text() );
  • option

    Signature:
    .multiselect( 'option', optionName, [value] )

    Get or set any dialog option. If no value is specified, will act as a getter.

  • select

    Signature:
    .multiselect( 'select', item )

    Select the specified item. The value should the text of the option to select (not case sensitive).

    If only the option key is known, the option may be specified using the following command:

    $('.mulstiselect').multiselect('select', $('.multiselect').find('option[value=key]').text() );
  • selectAll

    Signature:
    .multiselect( 'selectAll' )

    Select all of the available items.

  • selectedValues

    Signature:
    .multiselect( 'selectedValues' )

    Return an array of the keys of all the currently selected values.

    This method is an utility method equivalent to :

    $.map( $('.multiselect').find('option[selected]'), function(item,i) { return $(item).val(); });
  • selectNone

    Signature:
    .multiselect( 'selectNone' )

    Deselect all the selected items (equivalent to "Remove all").

All event callbacks receive two parameters: the event object and the ui object. The ui object's property may vary between events, but all share these basic properties:

  • ui.sender : the SELECT element where the event originated (use $(ui.sender).multiselect(...) to access widget)

  • deselected

    Type:
    multiselectdeselected

    This event is triggered whenever the an option has been deselected. The event deselected is triggered for every option deselected.

    Code examples

    Supply a feedback function to handle the deselected events as an init option.
    $('.selector').multiselect({ deselected: function(event, ui) { alert($(ui.option).val() + " has been deselected"); } });
    Bind to the deselected event of type multiselectdeselected.
    $('.selector').bind('multiselectdeselected', function(event, ui) {
      ...   // ui.option is the DOMOption node of ui.sender
    });
  • messages

    Type:
    multiselectmessages

    This event is triggered whenever the widget needs to send some feedback to the user.

    Code examples

    Supply a feedback function to handle the messages supplied by the widget as an init option. The ui object will hold these extra parameters:
    • ui.description : a preformatted message describing the event's message
    • ui.type : one of the following value: 0=message (warning), 1=exception, 2=error
    $('.selector').multiselect({ messages: function(event, ui) { alert(ui.description); } });
    Bind to the messages event of type multiselectmessages.
    $('.selector').bind('multiselectmessages', function(event, ui) {
      ...
    });
  • selected

    Type:
    multiselectselected

    This event is triggered whenever the an option has been selected. The event selected is triggered for every option selected.

    Code examples

    Supply a feedback function to handle the selected events as an init option.
    $('.selector').multiselect({ selected: function(event, ui) { alert($(ui.option).val() + " has been selected"); } });
    Bind to the selected event of type multiselectselected.
    $('.selector').bind('multiselectselected', function(event, options) {
      ...   // ui.option is the DOMOption node of ui.sender
    });