Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reset v-autocomplete programatically #66

Open
Hrddk opened this issue Jul 11, 2018 · 5 comments
Open

reset v-autocomplete programatically #66

Hrddk opened this issue Jul 11, 2018 · 5 comments

Comments

@Hrddk
Copy link

Hrddk commented Jul 11, 2018

Hello

Can you please also add support for reset component programmatically.
currently I'm using following way to reset component.

<v-autocomplete ref="auto-complate" placeholder="Search customer" :items="items"
:get-label="getLabel" :auto-select-one-item="false" :component-item='template'></v-autocomplete >

this.$refs['auto-complate'].searchText = "";
this.items = [];

data has this type of array:

items: [
  {first: "Item", last: "A"},
  {first: "Item", last: "B"},
  {first: "Item", last: "C"},
  {first: "Item", last: "D"},
] 

and
getLable method returns:

getLabel(item) {
  item.first + ' ' + item.last;
},

setting items all the time with [] (null array) and searchText with "" (empty string). so end user have to type again for new item.

@FelipeBohnertPaetzold
Copy link

You do not need to use a ref to clear the array of items, just clear on the component that is v-model.

<template>
  <v-auto-complete :items="fruits" ...></v-auto-complete>
</template>

<script>
export default {
  data () {
    return {fruits: ['apple', 'banana', 'strawberry']}
  },
  methods: {
    cleanListFruits () {
      this.fruits = []
    },
    ...
  }
}
</script>

@Hrddk
Copy link
Author

Hrddk commented Jul 11, 2018

@FelipeBohnertPaetzold I can't use v-model it throws error like Error in callback for watcher "value": "TypeError: Cannot convert undefined or null to object" and TypeError: Cannot convert undefined or null to object

@EnricoAlvarenga
Copy link

@Hrddk
Did you find some solution to your problem?

@Hrddk
Copy link
Author

Hrddk commented Nov 15, 2018

@EnricoAlvarenga Not yet I'm using above mentioned method for now.

@edwin1028
Copy link

@Hrddk This might be late but i'm having the same problem with the v-model, my solution is to check if item is null or not in your get-label function. That fixed the error. The only trouble i'm facing is how to reset the items when search text is empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants