darrenjennings / vue-autosuggest

🔍 Vue autosuggest component.
https://darrenjennings.github.io/vue-autosuggest
MIT License
621 stars 91 forks source link

Initial selected object #207

Open p0g opened 3 years ago

p0g commented 3 years ago

hi.

How to preselect an object value?

Using the v-model, is only setting the "userinput", but not the selected-value (and it only accept Strings)

See the forked sandbox where i try to set Gandalf at the inital, selected object, without any user-interaction. https://codesandbox.io/s/vueautosuggest-20-base-forked-cgy1s?file=/App.vue:2857-3206

This function is relevant for an project where i store the selected object in localstorage, to restore later without bother the user every time.

jesseschutt commented 3 years ago

Were you able to find a solution for this?

p0g commented 3 years ago

Were you able to find a solution for this?

No sorry, and i dont use this component anymore (to outdated)

darrenjennings commented 3 years ago

I think this would be a good addition. The v-model is only for the query, not the selected item. There was some initial hackery with setChangeItem, but providing a prop or other that can set the initial item would be good. initialSelected or something, open to ideas.

re: "too outdated" comment, I am curious if there is anything you feel is outdated with respect to Vue 2.x? I am currently porting it over to support Vue 3.x here: https://github.com/darrenjennings/vue-autosuggest/tree/next/v3

eliumoraes commented 3 years ago

I think this would be a good addition. The v-model is only for the query, not the selected item. There was some initial hackery with setChangeItem, but providing a prop or other that can set the initial item would be good. initialSelected or something, open to ideas.

re: "too outdated" comment, I am curious if there is anything you feel is outdated with respect to Vue 2.x? I am currently porting it over to support Vue 3.x here: https://github.com/darrenjennings/vue-autosuggest/tree/next/v3

Hello @darrenjennings! I'm using your component and am trying to set a default value from my :suggestions list. I would like to know if you can show how to, as you said, hack it, and set the default value.

eliumoraes commented 2 years ago

I think this would be a good addition. The v-model is only for the query, not the selected item. There was some initial hackery with setChangeItem, but providing a prop or other that can set the initial item would be good. initialSelected or something, open to ideas. re: "too outdated" comment, I am curious if there is anything you feel is outdated with respect to Vue 2.x? I am currently porting it over to support Vue 3.x here: https://github.com/darrenjennings/vue-autosuggest/tree/next/v3

Hello @darrenjennings! I'm using your component and am trying to set a default value from my :suggestions list. I would like to know if you can show how to, as you said, hack it, and set the default value.

I found the solution. The component accepts v-model, you can set the default value that way.