Vue-multiselect: Conditionally bind search-change event - how to pass in the search query

Created on 8 Jun 2017  路  1Comment  路  Source: shentao/vue-multiselect

How can I conditionally bind the search-change event?

Here鈥檚 my component:

<multiselect
            v-model="selected"
            :options="options"
            :placeholder="props.placeholder"
            :multiple="props.multiple"
            :loading="isLoading"
            @search-change="props.data ? asyncFind(this.search, this.id) : null"
        >
        </multiselect>

And the key part:

@search-change="props.data ? asyncFind(this.search, this.id) : null"

How can I pass in the search and id? If I use @search-change="props.data ? asyncFind : null" they are undefined.

question

Most helpful comment

This is limited by the way event handling in Vue works. You would have to do something like this:

@search-change="asyncFind($event, id)"

$event is always the 1st parameter passed to the event from within Multiselect.
After that change your asyncFind method like this:

asyncFind (query, id) {
  if (!this.props.data) return
  // do the async stuff with the query and id
}

That should solve the problem. Let me know if it doesn鈥檛.

>All comments

This is limited by the way event handling in Vue works. You would have to do something like this:

@search-change="asyncFind($event, id)"

$event is always the 1st parameter passed to the event from within Multiselect.
After that change your asyncFind method like this:

asyncFind (query, id) {
  if (!this.props.data) return
  // do the async stuff with the query and id
}

That should solve the problem. Let me know if it doesn鈥檛.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stefanheimann picture stefanheimann  路  4Comments

MaxHalford picture MaxHalford  路  4Comments

focussing picture focussing  路  3Comments

yaakovp picture yaakovp  路  3Comments

alexhyriavets picture alexhyriavets  路  3Comments