Move the chosen call to the update.
http://jsfiddle.net/jearles/avSfa/28/
-
ko.bindingHandlers.chosen = { init: function(element, valueAccessor, allBindingsAccessor, viewModel) { var allBindings = allBindingsAccessor(); var options = {default: 'Select one...'}; $.extend(options, allBindings.chosen) $(element).attr('data-placeholder', options.default); }, update: function(element, valueAccessor, allBindingsAccessor, viewModel) { $(element).chosen(); } };
-
Alternatively, you can use setTimeout to transfer the call to chosen to the bottom of the execution queue. This will give the Knockout options binding time to complete their work before the chosen tries to convert it.
ko.bindingHandlers.chosen = { init: function (element, valueAccessor, allBindingAccessor, viewModel, bindingContext) { var options = ko.utils.unwrapObservable(valueAccessor() || {}); setTimeout(function() { $(element).chosen(options); }, 0); } };
source share