Documentation for select javascript module.

Files

app/scripts/modules/Select.js

Select

Usage

Usage is shown in forms-basic section of this styleguide.

Default initialization

Initialization is shown on example below. Constructor returns array of select elements.

Defailt initialization is done in main.js file for all select elements with class .js-select.

Example:
Code:
<script>
  var mySelects = new myApp.Select();
  console.log(mySelects);
  // [{select object}, {select object}, ...]
  mySelects[0].disable();
  // etc..
</script>

Custom initialization

In case it's needed to create select with more customized behavior, all Choices.js options can be passed to myApp.Select constructor as second argument config.

Code:
<select id="myCustomSelect">
  <option value="test">Option</option>
  <option value="test">Better option</option>
</select>
<script>
  // custom selector
  var customSelect = new myApp.Select('#myCustomSelect', {
    shouldSort: false
  });
</script>

Options

Defaults

new Select([selector, [config]])

Name Type Default Description
selector String '.js-select' Default DOM selector.
config Object {} Config object. All config options from Choices.js are available.

DOM attributes

Available DOM attributes.

Name Type Default Description
data-clearable Boolean null If true, selected option can be cleared to placeholder or empty value with button.