ko.bindingHandlers.chosenOptions = {
init: function(element, valueAccessor, allBindings, data, context) {
var options = allBindings().chosenOptionsOptions || {}
ko.bindingHandlers.options.init(element, valueAccessor, allBindings, data, context)
var temp = $(element).chosen(options);
/*
*From what I can see, a width NEEDS to be set with chosenOptionsOptions: {width: "300px"} for the thing to work.
*Also, the object selected MUST come from the list, so you do a javascript find on the list to set it and everything will work.
*/
//This binds the jqueryChosen object to the chosenOptionsChosenObject variable name in the model
//It is used to add things to a multiple select
//in the html data-bind, add chosenOptionsChosenObject with a variable name
//this variable in the model is set to chosen.
//example
//say you want to insert this result: self.emailsChosenObject.results_data[17]
// you pick the html li thing by var temp = $('.chosenEmails *[data-option-array-index="17"]');
//you set self.emailsChosenObject.result_highlight = temp;
//then you call self.emailsChosenObject.result_select(new Event("email")) //you put the event to prevent a console error only
if (allBindings().chosenOptionsChosenObject) data[allBindings().chosenOptionsChosenObject] = temp.data().chosen
},
update: function(element, valueAccessor, allBindings, data, context) {
ko.bindingHandlers.options.update(element, valueAccessor, allBindings, data, context)
setTimeout(function() {
$(element).trigger('chosen:updated')
}, 50)
}