JSPM

  • Created
  • Published
  • Downloads 163278
  • Score
    100M100P100Q181464F
  • License MIT

A lightweight dependency-free javascript select box replacement.

Package Exports

  • mobius1-selectr

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mobius1-selectr) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Selectr Build Status npm version license

A lightweight dependency-free select box replacement written in vanilla javascript. Just 6KB minified and gzipped. Similar to Select2 and Chosen without the dependencies.

Supports most modern browsers including IE9.

Features:

  • Supports single and multiple select boxes
  • Supports optgroups
  • Searchable options
  • Tagging support
  • Custom events
  • Custom styling
  • Much more...

Demos | Documentation | Playground


Install

bower

bower install mobius1-selectr --save

npm

npm install mobius1-selectr --save

Browser

Grab the files from the CDN and include them in your page:

<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/selectr/2.1.4/selectr.min.css">

<script type="text/javascript" src="https://cdn.jsdelivr.net/selectr/2.1.4/selectr.min.js"></script>

CDN courtesy of jsDelivr


Initialisation

HTML

Start with a standard select box you want to convert:

<select id="mySelect">
    <option vlaue="value-1">Value 1</option>
    <option vlaue="value-2">Value 2</option>
    <option vlaue="value-3">Value 3</option>
    ...
</select>

Javascript

You can then instantiate Selectr by passing a reference to your select box as the first parameter as either a DOM node or a CSS3 selector string:

new Selectr(document.getElementById('#mySelect'));

// or 

new Selectr('#mySelect');

Selectr accepts the options object as a second parameter:

new Selectr('#mySelect', {
    searchable: false,
    width: 300
});

Change Log

v2.1.5

  • Improved accessibility
  • New methods disable() and enable() (see docs)
  • Fixed navigation bug (#5)

v2.1.4

  • Fixed form.reset() not resetting Selectr elements (#13)
  • Fixed autocomplete bug in Chrome (#12)
  • Fixed pagination not incrementing when navigating with the down key
  • Fixed reset() method not checking data

v2.1.3

  • Fixed bug with tagging system

v2.1.2

  • New option closeOnScroll (#11) (see docs)
  • Fixed bug with checking dropdown is on-screen (#10)
  • Fixed navigation bug (70168f2)

v2.1.1

  • new option allowDeselect (see docs)
  • tabIndex enabled on th main container
  • tabIndex disabled on search input when closed

v2.1.0

  • New tagging feature (see docs)

New functions:

  • addOption() (see docs)
  • serialize() (see docs)
  • destroy() (see docs)
  • render() (see docs)

New options:

  • taggable (see docs)
  • tagSeperators (see docs)

Updated options:

  • sortSelected (see docs)

License

Copyright 2016 Karl Saunders

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.