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

suggestions don't update on list prop change #301

Open
1 of 3 tasks
shrpne opened this issue Apr 3, 2020 · 3 comments
Open
1 of 3 tasks

suggestions don't update on list prop change #301

shrpne opened this issue Apr 3, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@shrpne
Copy link
Contributor

shrpne commented Apr 3, 2020

I'm submitting a ...

  • bug report
  • feature request
  • support request

What is the current behavior?

Updating list prop doesn't affect suggestions until input value change

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

https://jsfiddle.net/pq38tusw/1/

  • Click on the input to show suggestions
  • Click "Update list" button
  • Click on the input again and see, that list prop changed, but suggestions does not

What is the expected behavior?

suggestions should change accordingly to list, as if it was computed property of list

Please tell us about your environment:

  • Vue.js Version: 2.6.11
  • Vue-simple-suggest version: 1.10.1
  • Browser: Firefox, Chrome, most likely all
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

To fix it we can watch list prop and do research() in the watcher.

But list prop also can be a function, and in such case, we can't watch it:

methods: {
  getList() {
    return this.list;
  }
}
<vue-simple-suggest list="getList"/>

https://jsfiddle.net/pq38tusw/2/

I propose to throw on non-async functions and guide users to use Array instead of a non-async function so they will not be caught by such bug.

@shrpne shrpne mentioned this issue Apr 3, 2020
3 tasks
@dhruvaaronwalter
Copy link

dhruvaaronwalter commented Apr 3, 2020

You can use clearSuggestions() method to get rid of previous suggestions when you are updating your list. I believe its easier than using watchers which i personally don't like using. So your code (the first one) looks like this:
Component declaration (adding ref) --
<vue-simple-suggest v-model="chosen" :min-length="0" :list="list" :ref="'suggestion'"> <!-- Filter by input text to only show the matching results --> </vue-simple-suggest>

updateList function (using ref to call clearSuggestions)--
updateList() { this.$refs.suggestion.clearSuggestions(); this.list = [ 'One', 'Two', 'Three', ] }

@shrpne
Copy link
Contributor Author

shrpne commented Apr 3, 2020

Thank you for proposing workaround, but I think that clearSuggestions will not work perfectly

  • in my production code, list is a computed property, so I do not really call a method to update it
  • clearSuggestions only help to refresh suggestions on open. But if dropdown is already opened and update happens at this time, clearSuggestions will lead to empty open list

@kaskar2008 kaskar2008 added the bug Something isn't working label Apr 3, 2020
@tmnaeem
Copy link

tmnaeem commented Sep 7, 2022

You can try to use this.$refs.suggestion.suggestions = this.list after you have updated the list using their ref data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants