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

Is it possible to set initial-value after the component is initialized? #95

Closed
wujekbogdan opened this issue Feb 24, 2019 · 4 comments
Closed

Comments

@wujekbogdan
Copy link

I'd like to set the initial-value but the source of the value is asynchronous, so I need to do it after the vue-autosuggest component is initialized. I've looked at the source code and it seems that the initial value is set when the component is created so it's not reactive. The only way I found is to access the input element via ref... which doesn't seem very elegant.

Is there any better way of changing the input's value after the component is initialized?

@darrenjennings
Copy link
Owner

@wujekbogdan yes! this is something I fixed in 2.0. I would recommend upgrading to the latest beta https://www.npmjs.com/package/vue-autosuggest/v/2.0.0-beta.6 which would give you v-model support, removes initialValue entirely, and thus gives you a way to programmatically control the value. If that sounds daunting, you can always just throw a v-if on the component and wait for the initialValue to be available. This is less than ideal because users won't see the component until the value is ready, so would recommend upgrading.

@wujekbogdan
Copy link
Author

@darrenjennings
Thanks! And also thanks for the vue-autosuggest component. It does exactly what I need, it's simple, flexible, and what's most important for me - it doesn't load its own CSS (which is not very common in Vue-world!).

@puremana
Copy link

It worked to v-model, but broke my shouldRenderSuggestions() setup and this.$refs.autosuggest.loading values for some reason.

@darrenjennings
Copy link
Owner

@puremana happy to help if you have a codesandbox for reproducing.

Fork this one for 1.x: https://codesandbox.io/s/vueautosuggest-api-clicking-things-in-the-headerfooter-bzdrp
Fork this one if you're on the beta: https://codesandbox.io/s/x9z1lo20mo

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

3 participants