Trying to use jquery-chosen with vue, the problem is that this plugin hides the actual select that I applied v-model, so when I select a value vue doesn't recognize it as a select change event and model value is not updated.
I've seen some solution available for Vue 1 that don't work with Vue 2
It's showing the current value but doesn't know how to set so that model value changes.
Vue.directive('chosen', {
twoWay: true, // note the two-way binding
bind: function(el, binding, vnode) {
Vue.nextTick(function() {
$(el).chosen().on('change', function(e, params) {
alert(el.value);
}.bind(binding));
});
},
update: function(el) {
// note that we have to notify chosen about update
// $(el).trigger("chosen:updated");
}
});
var vm = new Vue({
data: {
cities: ''
}
}).$mount("#search-results");
The preferred method of integrating jQuery plugins into Vue 2 is to wrap them in a component. Here is an example of your Chosen plugin wrapped in a component that handles both single and multiple selects.
And this is an example of usage in a template:
Fiddle for multiple select.
Original Answer
This component doesn't handle multiple selects correctly, but leaving it here because it was the original answer that was accepted.
This component supports v-model. So that you can use it in your template like so:
Here is your fiddle updated.