Ciasto piekarz
Ciasto piekarz

Reputation: 8277

v-on:change does not work for vue-multiselect

I am using vue-multiselect component in my vue.js project, I am using v-on directive to execute a function on the change event ,

<multiselect v-model="selected" :options="projects" :searchable="false" :custom-label="customLabel" track-by="name" v-on:change="executeLoader">
<template slot="customLabel" slot-scope="{ customLabel }"><strong>{{ option.name }}</strong></template>   
</multiselect>

I have example full code here: https://codesandbox.io/s/yjjon0vzxj

the v-on:change was working with <select> component but it stopped workigng with vue-multiselect ! I tried with v-on:click="executeLoader" but that too didnt worked either..

Upvotes: 5

Views: 27663

Answers (3)

Daniel
Daniel

Reputation: 8657

If you reading this in 2024 you probably using Vue 3 so try

      <multiselect
        ...
        @update:model-value="apply"
      />

Upvotes: 0

Omar Tanti
Omar Tanti

Reputation: 1448

@click will not trigger the method executeLoader with vue multiselect. You can use @input - which is similar to v-on:change, @close, @select as in example below:

<multiselect placeholder="Pick at least one"
  select-label="Enter doesn’t work here!"
  :value="value"
  :options="options"
  :multiple="true"
  :searchable="true"
  :allow-empty="false"
  :hide-selected="true"
  :max-height="150"
  :max="3"
  :disabled="isDisabled"
  :block-keys="['Tab', 'Enter']"
  @input="onChange"
  @close="onTouch"
  @select="onSelect">
</multiselect>

In your case I would try @input="executeLoader"

Upvotes: 17

samayo
samayo

Reputation: 16495

In vue-multiselect, since it is a component you can't treat it to behave like a simple <select> element.

In components, when you expect them to behave and "listen" to click events just like other html tag, then you should add an event modifier called: .native.

So, you can do on any component:

<... @click.native="executeLoader" />

But that is not what you are looking for I think. You want to trigger a function when you add more and more tags, or in short: when the selected items increase.

for that, vue-multiselect exposes the @input event, so you can handle using:

<... @input="executeLoader" />

And now just call executeLoader and accept the arguments as:

methods: {
  executeLoader(selectedItems) {} 
}

Upvotes: 1

Related Questions