BosNaufal / vue2-autocomplete

Vue 2 Component to make Autocomplete element.
MIT License
233 stars 89 forks source link

Pass data to function onSelect in loop #48

Open Konafets opened 7 years ago

Konafets commented 7 years ago

Hi,

I iterate over an array of items. Per iteration the user has a <autocomplete> field which sets the selected data to the model.

<div id="tests_container" v-for="(item, index) in items">
    <autocomplete
        required
        url="{{ route('api:products:search') }}/"
        :classes="{input: 'form-control', list: ''}"
        :id="'test_' + index + '_front_wheel'"
        :name="'test_' + index + '_front_wheel'"
        :custom-params="{ type: 'wheel' }"
        data-test="test"
        anchor="title"
        label="title"
        :on-select="setFrontWheel"
        :min="3"
        :init-value="test.front.wheel.title"
        tabindex="5"
    ></autocomplete>
    <input type="hidden" :id="'test_' + index + '_front_wheel_id'" :name="'test_' + index + '_front_wheel_id'" v-model="test.front.wheel.id">
</div>

I like to use the hidden input to set the selected id like so:

searchFrontWheel(obj, test){
    test.front.wheel.id = obj.id;
}

and pass test to setFrontWheel(test) on the component. But this does not seems to work. The method is called when the component is loaded but not when I select an item. Is there a way to do this?

molerat619 commented 6 years ago

Have you found a way to achieve this?

yordivd commented 6 years ago

I would like to know this as well...