shentao / vue-multiselect

Universal select/multiselect/tagging component for Vue.js
https://vue-multiselect.js.org/
MIT License
6.71k stars 988 forks source link

how to set selected? :value prop is ignored #1189

Open vue-fan opened 4 years ago

vue-fan commented 4 years ago

Steps to reproduce

 <multiselect
        v-model="form.empresa"
        :value="form.empresa"
        :options="empresas"
        :multiple="false"
        track-by="id"
        label="empresa"
        tag-placeholder="{{ __('Select Empresa') }}"
        placeholder="{{ __('Empresa') }}">
        </multiselect>

import AppForm from '../app-components/Form/AppForm';

Vue.component('admin-user-form', {
    mixins: [AppForm],
    props: ['empresas'],
    data: function() {
        return {
            form: {
                first_name:  '' ,
                last_name:  '' ,
                email:  '' ,
                password:  '' ,
                activated:  false ,
                forbidden:  false ,
                language:  '' ,
                empresa:  '' ,

            }
        }
    }
});

Expected behaviour

i wanto to set the selected options when im editing an item

Actual behaviour

it doesn't work

davevasquez commented 1 year ago

Having a similar issue. No matter what value I set :value to, it fails to represent this. v-model functions as expected, but :value appears to have no effect, even in a simple implementation like this:

const testValue = ref('foo');
const testOptions = ref(['foo', 'bar', 'baz']);

<VueMultiselect :value="testValue" :options="testOptions" ...>

The result is a list of my options in the dropdown, but 'foo' is not preselected as would be expected.

nthndnn commented 1 year ago

I've just tried and had no luck with this either, the fact that this is three and a half-year-old issue and hasn't been addressed is quite concerning...

mattelen commented 1 year ago

Hi there. Can we have a reproduce-able example using something like https://jsfiddle.net/mattelen/8cyt3hrn/5/ or something similar. @nthndnn since you've had this one recently, it would be great an example so I can jump in and see what is going on, and issue a fix if needed. TIA