Skip to content

Instantly share code, notes, and snippets.

@yeco
Last active December 22, 2015 17:19
Show Gist options
  • Save yeco/6505605 to your computer and use it in GitHub Desktop.
Save yeco/6505605 to your computer and use it in GitHub Desktop.
Chosen.js v0.12 implementation in Ember 1.0.0.
App.ChosenSelect = Ember.Select.extend({
chosenOptions: {width:'100%', search_contains: true},
multiple:true,
attributeBindings:['multiple'],
didInsertElement: function(){
var view = this;
this._super();
view.$().chosen(view.get('chosenOptions'));
// Observes for new changes on options to trigger an update on Chosen,
// assumes optionLabelPath is something like "content.name"
return this.addObserver(this.get("optionLabelPath").replace(/^content/, "content.@each"), function() {
return this.rerenderChosen();
});
},
_closeChosen: function(){
// trigger escape to close chosen
this.$().next('.chzn-container-active').find('input').trigger({type:'keyup', which:27});
},
rerenderChosen: function() {
this.$().trigger('chosen:updated');
}
});
{{view App.ChosenSelect
contentBinding="options"
valueBinding="selectedOption"
optionLabelPath="content.name"
}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment