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.
The value of the select is being changed actually when I select something, I've inspected this with console.log to see the selected value.
http://jsfiddle.net/qfy6s9Lj/3/
I could do vm.$data.city = $('.cs-select').val()
, that seems to work,
But is there another option? If the value of the select was changed why vue doesn't see this?
I am opened for other suggestions, but for the time-being I did it this way:
html
js
Code taken from @kaktuspalme answer. It works with non-multiple elements now and only for non-multiple.
Comments from @Tyler Collier are taken into account
But be carefully,property you use in v-model should be defined as array , e.g. applicantId: [] otherwise it doesn't work
I made an update for vue2.
See: https://jsfiddle.net/kaktuspalme/zenksm2b/
Update: Be advised this doesn't work from within a
v-for
loop. A related question that deals with that is available here.Going off of @kaktuspalme's solution, and with help from my friend Joe Fleming, I came up with a solution that works with Vue 2 and allows single and multiple selections:
Use it like this:
It works with
multiple="multiple"
and even with nested state, e.g.:See the fiddle here: https://jsfiddle.net/tylercollier/bvvvgyp0/5/
Answer: http://jsfiddle.net/qfy6s9Lj/5/
UPDATE: an even better solution (thanks to simplesmiler): http://jsfiddle.net/simplesmiler/qfy6s9Lj/8/
@swift's answer got pretty close, but as @bertrand pointed out, it doesn't work for multiselects. I've worked something out that works with both cases: http://jsfiddle.net/seanwash/sz8s99xx/
I would have just commented but I don't have enough rep to do so.