Skip to content

Instantly share code, notes, and snippets.

@msarchet
Created June 9, 2012 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msarchet/2901816 to your computer and use it in GitHub Desktop.
Save msarchet/2901816 to your computer and use it in GitHub Desktop.
Simple Chosen.js binding handler for knockoutjs
//knockout.js can be found at http://www.knockoutjs.com
//chosen.js can be found at http://harvesthq.github.com/chosen/
//jquery.js can be found at http://jquery.com
//Usage is data-bind="chosen: true"
//Want to clean this up to eventually work as
//data-bind="chosen: { options: SelectOptions, value: selectValue}"
ko.bindingHandlers.chosen = {
init: function(element, valueAccessor, allBindingsAccessor, viewModel) {
$(element).chosen();
},
update: function(element, valueAccessor, allBindingsAccessor, viewModel) {
$(element).trigger("liszt:updated");
}
};
Copy link

ghost commented Feb 18, 2014

this binding is not working for knockout js v3.0

@mcarpenterjr
Copy link

mcarpenterjr commented Oct 6, 2017

line 16: should be $(element).trigger("chosen:updated)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment