This addon allows you to use the popular Chosen jQuery plugin in your ember-cli application.
ember-cli-chosen works with ember-cli version '0.1.5' or later
Always view the latest readme via Github!
ember install:addon ember-cli-chosen
There are two different build options you can supply to customize what Chosen files are included in your build.
By default, ember-cli-chosen
will provide the version of Chosen that includes jQuery (chosen.jquery.js
).
To use the version of Chosen without jQuery, specify false
for the jQuery
property.
var EmberApp = new EmberApp({
'ember-cli-chosen': {
'jQuery': false
}
});
By default, ember-cli-chosen
will include Chosen's CSS (as well as its sprites) in the build.
To prevent Chosen's CSS from being included in the build, specify false
for the importChosenCSS
property.'
NOTE: Specifying false
for the importChosenCSS
property will also cause the Chosen sprites to be removed from the build.
var EmberApp = new EmberApp({
'ember-cli-chosen': {
'importChosenCSS': false
}
});
In a template, render the component via ember-chosen
:
{{#ember-chosen}}
<option value="1">Tom Dale</option>
<option value="2">Yehuda Katz</option>
...
{{/ember-chosen}}
ember-cli-chosen
allows you to specify values for all of the available options that Chosen exposes.
All of the options below are watched for changes. If a change occurs, Chosen is re-initialized with the updated options.
The number of options at which the search functionality should be disabled.
{{#ember-chosen disableSearchThreshold=10}}
...
{{/ember-chosen}}
Right-to-left mode. This will add the chosen-rtl
class to the select input.
{{#ember-chosen isRtl=true}}
...
{{/ember-chosen}}
Set the maximum allowed number of selected options.
{{#ember-chosen maxSelectedOptions=5}}
...
{{/ember-chosen}}
Allows multiple selections.
{{#ember-chosen multiple=true}}
...
{{/ember-chosen}}
The text to be displayed when no results are available as a result of a search.
{{#ember-chosen noResultsText="Sorry, nothing to display!"}}
...
{{/ember-chosen}}
The placeholder for your Chosen input. This will set the data-placeholder
attribute.
NOTE: For prompt
to be displayed for single item select inputs, you must provide an empty <option>
as the first
option for your input
{{#ember-chosen prompt="Select one..."}}
<option></option>
...
{{/ember-chosen}}
Sets the width of the input.
Default: "100%"
ember-cli-chosen
supports the following actions:
The action fired when the user updates their selection. For multiple select inputs, this includes selection AND deselection.
Note: For multiple selects, the parameter passed to your action is an array of the currently selected items.
{{#ember-chosen selectionDidChange="onSelectionChanged"}}
...
{{/ember-chosen}}
export default Ember.Controller.extend({
// Controller implementation
actions: {
onSelectionChanged: function(selectedValue) {
// selectedValue will be a single value for single selects
// and an Array for multiple selects
console.log('User selected:', selectedValue);
}
}
});
The action fired when maxSelectedOptions
has been set and the user tries to select an additional value after
maxSelectedOptions
has been met.
{{#ember-chosen multiple=true maxSelectedOptions=5 chosenMaxSelected="onChosenMaxSelected"}}
...
{{/ember-chosen}}
export default Ember.Controller.extend({
// Controller implementation
actions: {
onChosenMaxSelected: function(e, chosen) {
// e: jQuery Event
// chosen: The Chosen object for the input that triggered the event
alert("You can't do that!");
}
}
});