Selectator is a jQuery-based replacement for select boxes

Overview

DEPRECATED - no longer actively maintained

Selectator

Selectator is a jQuery-based replacement for select boxes. It supports searching, custom renderers, remote data (ajax), search delay, minimum search length, selection remove/clear and placeholders. It affects the original select box directly, which is used as the data container. You can see a demo here.

Usage

include in head:
<link rel="stylesheet" href="fm.selectator.jquery.css"/>
<script src="jquery-1.11.0.min.js"></script>
<script src="fm.selectator.jquery.js"></script>
to activate replacement:
$('#selectBox').selectator();

If you don't wan't to meddle with scripting, there is an alternative to activate replacement, by using inline markup.

<select multiple class="selectator" data-selectator-keep-open="true">
if you want to change settings:
$('#selectBox').selectator({
    prefix: 'selectator_',             // CSS class prefix
    height: 'auto',                    // Auto or element
    useDimmer: false,                  // Dims the screen when option list is visible
    useSearch: true,                   // If false, the search boxes are removed and 
                                       //   `showAllOptionsOnFocus` is forced to true
    showAllOptionsOnFocus: false,      // Show the dropdown immediately when the control receives focus
    selectFirstOptionOnSearch: true,   // Selects the topmost option on every search
    keepOpen: false,                   // If true, then the dropdown will not close when 
                                       //   selecting options, but stay open until losing focus
    submitCallback: function(value){}, // Callback function when enter is pressed and 
                                       //   no option is active in multi select box
    placeholder: '',                   // Placeholder text for the select, can also be 
                                       //   set on select element
    load: function(search, callback){  // Callback function when using remote data
        callback(results);
    },
    delay: 0,                          // The amount of milleseconds to wait for doing a search
    minSearchLength: 0,                // Mininum length of search string required for searching
    valueField: 'value',               // The name of the property to use as the "value"
                                       //   (not needed when custom rendering functions are defined)
    textField: 'text',                 // The name of the property to use as the "text"
                                       //   (not needed when custom rendering functions are defined)
    searchFields: ['value', 'test'],   // The fields to search in
    render: {
        selected_item: function (_item, escape) {
            var html = '';
            if (typeof _item.left !== 'undefined') 
                html += '<div class="' + self.options.prefix + 'selected_item_left"><img src="' + escape(_item.left) + '"></div>';
            if (typeof _item.right !== 'undefined') 
                html += '<div class="' + self.options.prefix + 'selected_item_right">' + escape(_item.right) + '</div>';
            html += '<div class="' + self.options.prefix + 'selected_item_title">' + ((typeof _item.text !== 'undefined') ? escape(_item.text) : '') + '</div>';
            if (typeof _item.subtitle !== 'undefined') 
                html += '<div class="' + self.options.prefix + 'selected_item_subtitle">' + escape(_item.subtitle) + '</div>';
            html += '<div class="' + self.options.prefix + 'selected_item_remove">X</div>';
            return html;
        },
        option: function (_item, escape) {
            var html = '';
            if (typeof _item.left !== 'undefined') 
                html += '<div class="' + self.options.prefix + 'option_left"><img src="' + escape(_item.left) + '"></div>';
            if (typeof _item.right !== 'undefined') 
                html += '<div class="' + self.options.prefix + 'option_right">' + escape(_item.right) + '</div>';
            html += '<div class="' + self.options.prefix + 'option_title">' + ((typeof _item.text !== 'undefined') ? escape(_item.text) : '') + '</div>';
            if (typeof _item.subtitle !== 'undefined') 
                html += '<div class="' + self.options.prefix + 'option_subtitle">' + escape(_item.subtitle) + '</div>';
            return html;
        }
    },
    labels: {
        search: 'Search...'            // Placeholder text in search box in single select box
    }
});
Extra attributes for option tags

By using data-left, data-right, data-subtitle or any other attributes you can extend the information made available to the renderers. The default ones left, right and subtitle can be styled through css, and are named prefix_title, prefix_left, prefix_right and prefix_subtitle. The class attributes from the original option and optgroup elements are also added to the genererated elements

<select id="selectBox">
    <!-- Normal option tag -->
    <option value="1">This is the title</option>
    <!-- Extended option tag -->
    <option value="2" data-left="This is the left section" data-right="This is the right section" data-subtitle="This is the section under the title">This is the title</option>
</select>

It will be displayed something like this this:

Left Title Right
Subtitle

CSS classes

Here is a list of all the css classes

Class Description
prefix_element This is the new select box. It has some extra classes called single and multiple, which tell if it is a multiple selection or single selection select box. And also options-visible and options-hidden which tell if the options list is visible or not.
prefix_selected_items The holder for the selected items.
prefix_selected_item The holder for the selected item.
prefix_selected_item_title The title of the selected item.
prefix_selected_item_left The left section of the selected item.
prefix_selected_item_right The right section of the selected item.
prefix_selected_item_subtitle The bottom section of the selected item.
prefix_selected_item_remove The remove button for the selected item.
prefix_input This is the input box for the selectator. This is used together with options-visible or options-hidden to show and style it differently if it is a multiple selection box or a single selection box.
prefix_textlength This is used to calculate the size of the input box for the multiple selection box.
prefix_options The options list holder. This is used together with options-visible or options-hidden to show or hide the options.
prefix_group_header This is the group title option.
prefix_group This is the group options holder.
prefix_option This is a result option. It has an extra class called active which tells if the option is the active one.
prefix_option_title The title of the result option.
prefix_option_left The left section of the result option.
prefix_option_right The right section of the result option.
prefix_option_subtitle The bottom section of the result option.
prefix_mask This is the mask (dimmer)

DOM Structure

  • mask
  • element: containing the single|multiple class and the options-visible|options-hidden class
    • textlength
    • selected_items
      • selected_item
        • selected_item_left
        • selected_item_right
        • selected_item_title
        • selected_item_subtitle
        • selected_item_remove
      • selected_item...
    • input
    • options
      • group_header
      • group
        • option: containing the active class
          • option_left
          • option_right
          • option_title
          • option_subtitle
        • option...
      • option: containing the active class
        • option_left
        • option_right
        • option_title
        • option_subtitle
      • option...

jQuery methods

Method Description
removeSelection This method is used to deselect current option, if applicable.
hideDropdown This method is used to options dropdown.
refresh This method is used to refresh the plugin. A scenario where this would be useful is if the data in the original select box is changed by some other script.
destroy This method is used to remove the instance of the plugin from the select box and restore it to its original state.
Method usage
$('#selectBox').selectator('removeSelection');
$('#selectBox').selectator('hideDropdown');
$('#selectBox').selectator('refresh');
$('#selectBox').selectator('destroy');

Browser compatibility

  • IE 8+
  • Chrome 2+
  • Firefox 3.5+
  • Safari 4+
  • Opera 11+

Internationalization

Selectator supports language by setting labels through the plugin options.

Copyright and license

The MIT License (MIT)

Copyright (c) 2013 Qodio

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • Selectator not working on every reload

    Selectator not working on every reload

    I like the selectator - really cool plugin. So I use it every time in my applications I need select-elements. There is only one problem:

    On a "normal" page the selectator works on every reload. If I have the selecator within a jQuery page which I get by load(), it doesn't work on every reload. If I refresh the page again, again and again, the selectator doesn't affect after x tries. The number of tries varies. In case of this problem there ist still no message in developer console or something - the element only stays the standard html select.

    selectator-not-working

    Is there some trick, or delay, or something else I can try? I still put the .selecator in a document ready function, but still the same problem.

    opened by florianwaesch 4
  • IPAD close dropdown issue

    IPAD close dropdown issue

    Hi

    I noticed that once you open the dropdownlist on an IPAD it's not possible to close the dropdownlist again without selection something in the list first.

    On desktop you can just click anywere else on the website and it will close the dropdownlist, but tapping anyway on the website on IPAD don't close the dropdown.

    I tried on your test site and it's the same issue, but tapping the labels above the dropdown does close the dropdown though.

    Isn't this a bug?

    opened by BilalW 4
  • Selectator Dropdown not working properly on Safari

    Selectator Dropdown not working properly on Safari

    While selecting option from the dropdown, the value is not getting updated, instead dropdown shows selected item beneath the previous selection. The content is getting outside the element. selectator

    opened by metajunaid 3
  • IE8

    IE8

    You plugin does not work in IE8, maybe even IE9. Although it does open the a list as a dropdownbox it does NOT allow you to select a item in the list. The list stays open and nothing happens.

    opened by BilalWachah 3
  • New feature: classes

    New feature: classes

    For my application I would like to hide certain elements from the list, but still have them be searchable. To accomplish this, a custom class can be added with data-class on an option element to have the class appended to the resulting li element.

    This feature can also be used to highlight certain options, etc.

    opened by debano 3
  • Can't click on an option with mouse

    Can't click on an option with mouse

    Hi, I found your script for showing pictures in a select element and like it much. Unfortunately I can't make it run correctly. When using the script I can't click on an option from the drop down list. Also the mouse pointer won't change the appereance to the fingers like the pointer in the demo. When I choose an option with the keyboard it will work. Do you have an idea what could be the problem?

    opened by newmicha 2
  • placeholder does not work

    placeholder does not work

    I use selector like this:

    <select id="selectId" style="width: 100%;">
      <option value="1">One</option>
      <option value="2">Two</option>
    </select>
    
    function(){
      $selectId.selectator({
    	useDimmer:true,
            placeholder:'Click to search...'
      });
    };
    

    Everything is ok, but the first option is selected after the page loads instead of displaying placeholder. Why it does not work as expected, Am I missed something?

    opened by biaderbia 2
  • Text going out of box

    Text going out of box

    If a select option has a text, which is longer than the select box and then you activate selectator, the text will go out of the box.

    Reproduce: Win 7, Firefox 38.0.1 http://opensource.faroemedia.com/selectator/

    Replace with below select option, click on activate selectator.

    <select style="display: none;" id="select2" name="select2">
                <option value="1" class="option_one">One one one one One one one one One one one one One one one one</option>
                <option value="2" class="option_two">Two</option>
            </select>
    

    -> Text goes out of box

    opened by blincivi 2
  • costomizing selectator plugin

    costomizing selectator plugin

    Hi, I use selectator plugin and I wanted to say thank you. I have a question for you.

    I want that user can select at last 4 items in multi select mode. How can I do that?

    Thank you very much for answering my question.

    • Hashem
    opened by tashkartal 1
  • Issue in Docs with the JQ method Refresh

    Issue in Docs with the JQ method Refresh

    In docs on Git you've written, that refreshing of the selectator can be triggered by 'refreshChosenItems' function. Actually, in code this function is just 'refresh', it baffles a bit before code analysys. Thank you for the plugin)

    opened by Morjodrom 1
  • Not display Input Search Element

    Not display Input Search Element

    Hi

    I like your plugin very much. It's working very well, but I was wondering how to turn off the "search" function. Because in my case I have few options to choose so there is no need for "input search element". How can I hide this element.

    If you can help, I'd be grateful.

    Best regards, Gregg

    enhancement 
    opened by grzegorzjawo 1
  • Trigger reset selected or change data values

    Trigger reset selected or change data values

    Hi,

    I'm working on a form that allows to edit a product and its variations. My (single) Selectators are therefore filled with data proceeding from the DB, retrieving the previously both selected and unselected options.

    On click on a "Clear data" button, (I have several ones along my form), I'm trying to either :

    • change the content of a selected item (value, data-left, text...) or
    • append a new empty option as selected, with value, data-left & text ="" or
    • trigger click on Selectator close button. // $("#variation_1 .selectator_selected_item_remove").trigger('click'); doesn't work. How do I target it ?

    None of these solutions work, and it's a little brainstorming as it reads divs instead of options in the console.

    Anticipate thanks & regards :)

    opened by Contemp 1
  • Auto Select a Option programatically on page loads when using remote search

    Auto Select a Option programatically on page loads when using remote search

    I'm using remote search where I'm searching for customers to place an order for them. But on the "Update Order" page I want to select that particular user automatically when the page loads. But remember the remote search should be enabled so I can change the customer by searching remotely.

    opened by imadarshap 1
  • Select from dropdown using outside click link

    Select from dropdown using outside click link

    Hello, I like this script very much but there is something I can't make work.

    For a simple