Vue-select: Clear selection after Input

Created on 30 Jul 2018  路  2Comments  路  Source: sagalbot/vue-select

I'm using vue-select component to search items from an API. After the user has clicked on an Item, I add it to a shopping cart through the @input trigger.

I would like to clear the selection after this, so I actually don't ever need a value to be selected. Is there any option to do this? or any code I can use in the @input trigger?

Here is my example:

<v-select ref='theSelect' v-model="selected" placeholder="Search Items..." label="name" :filterable="false" :options="options" @search="onSearch" @input="addItem(selected)">

addProduct(selected) {
      if (selected != null) {
        alert(selected.id);      
        this.addtocart(selected);
        this.$refs.theSelect.clearSelection();      
        this.selected = null;     
      }      
    }

This is working, but I wonder if there's a better way to get this done.

Most helpful comment

I am also doing this and I think it would be easier if we could get a reference to the vue-select instance in the onChange handler

All 2 comments

I am also doing this and I think it would be easier if we could get a reference to the vue-select instance in the onChange handler

I'm going to close this issue, but ensuring that all events receive the VM instance is high on my list.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ducdev picture ducdev  路  3Comments

fabianmieller picture fabianmieller  路  3Comments

gilles6 picture gilles6  路  3Comments

FrozenIce0617 picture FrozenIce0617  路  3Comments

twz915 picture twz915  路  3Comments