Comments (15)
I managed to come up with a work-around by setting the ref
attribute on the component and then using this.$refs.refName.inputValue = 'Some value'
.
<vue-bootstrap-typeahead
v-model="town"
:data="towns"
:inputClass="'large-input'"
placeholder="Enter your town or city"
ref="townTypeahead"
/>
Then in the mounted()
lifecycle, use:
this.$refs.townTypeahead.inputValue = 'London'
from vue-bootstrap-typeahead.
Would love to know if this is actually something we've both misunderstood. Great component but this feels like a basic feature that should work? I've just had exactly the same issue - despite setting v-model to the text I wanted displayed, it simply wouldn't show the value. I've found a work around by looking at the sourcecode but I'll add a warning:
Those of a weak disposition, look away now. Those easily offended should also look away.
My component setup is like this:
Component/HTML
<vue-bootstrap-typeahead ref="typeahead" :data="addresses" v-model="addressSearch" :serializer="s => locationText(s)" @hit="locationSelected" />
Where you want to set the initial selection
this.$refs.typeahead.$data.inputValue = this.locationText(val)
LocationText() is just a method I'm using to format the text as I want it - nothing special
Now that's out of the way - here's my use case incase I misunderstood you:
- User clicks a record from a table and a record is retreived from the database. Part of the record contains an id to a location object and the location object itself (basically, a region and postcode/zip code).
- Form is loaded with record and the location object's text representation is shown (concatenated text) inside the typeahead.
- User clicks in field to edit and when typing it will suggest records.
- On select, the id of the record selected is put into the location id field.
But obviously, when binding the initial location object, nothing was coming up. I found the only way to do it was reaching inside the typeahead component and setting the value it uses internally. I'm not sure what effect this will have on other aspects, but it works for me. I'm using NUXT FWIW
from vue-bootstrap-typeahead.
I managed to come up with a work-around by setting the
ref
attribute on the component and then usingthis.$refs.refName.inputValue = 'Some value'
.<vue-bootstrap-typeahead v-model="town" :data="towns" :inputClass="'large-input'" placeholder="Enter your town or city" ref="townTypeahead" />
Then in the
mounted()
lifecycle, use:
this.$refs.townTypeahead.inputValue = 'London'
This is great, but we shouldn't have to be doing this. v-model should just work on this component... so there is a bug in there somewhere, although I just started using this and didn't look at the code.
from vue-bootstrap-typeahead.
I managed to come up with a work-around by setting the
ref
attribute on the component and then usingthis.$refs.refName.inputValue = 'Some value'
.<vue-bootstrap-typeahead v-model="town" :data="towns" :inputClass="'large-input'" placeholder="Enter your town or city" ref="townTypeahead" />
Then in the
mounted()
lifecycle, use:
this.$refs.townTypeahead.inputValue = 'London'
This doesn't working for me :/, some idea?
from vue-bootstrap-typeahead.
I believe that I've merged a fix for this into my fork (https://github.com/mattzollinhofer/vue-typeahead-bootstrap) of this project that I'm actively maintaining. Give it a try and let me know if this is still an issue!
You can find it on npm here: https://www.npmjs.com/package/vue-typeahead-bootstrap.
I hope this helps!
from vue-bootstrap-typeahead.
@stefandunn Much neater fix. I hadn't thought about just omitting the $data (I'm still picking vue up). Cheers.
I also note that there is a branch of this project with this issue updated but it hasn't been merged.
from vue-bootstrap-typeahead.
I believe that I've merged a fix for this into my fork (https://github.com/mattzollinhofer/vue-typeahead-bootstrap) of this project that I'm actively maintaining. Give it a try and let me know if this is still an issue!
You can find it on npm here: https://www.npmjs.com/package/vue-typeahead-bootstrap.
I hope this helps!
Thank you. This is working!
from vue-bootstrap-typeahead.
Creo que he fusionado una solución para esto en mi fork ( https://github.com/mattzollinhofer/vue-typeahead-bootstrap ) de este proyecto que mantengo activamente. Pruébalo y avísame si esto sigue siendo un problema.
Puede encontrarlo en npm aquí: https://www.npmjs.com/package/vue-typeahead-bootstrap .
¡Espero que esto ayude!
Perfecto funciona !!!
from vue-bootstrap-typeahead.
That's exactly the case. Thanks for coming up with the detailed description.
from vue-bootstrap-typeahead.
from vue-bootstrap-typeahead.
from vue-bootstrap-typeahead.
@alexurquhart Is this repository no longer maintained?
from vue-bootstrap-typeahead.
I just double checked this issue and it is resolved on my branch. You can now set the initial value and update it as necessary. Report any more issues here https://github.com/mattzollinhofer/vue-typeahead-bootstrap/issues
from vue-bootstrap-typeahead.
I believe that I've merged a fix for this into my fork (https://github.com/mattzollinhofer/vue-typeahead-bootstrap) of this project that I'm actively maintaining. Give it a try and let me know if this is still an issue!
You can find it on npm here: https://www.npmjs.com/package/vue-typeahead-bootstrap.
I hope this helps!
That broke the serializer. It now shows [Object object].
from vue-bootstrap-typeahead.
That broke the serializer. It now shows [Object object].
@pappascd81: Interesting, it's working well on my end and others are reporting success. If you can provide a few more details as a new issue on the new repo I can try and see what's going on: https://github.com/mattzollinhofer/vue-typeahead-bootstrap/issues
from vue-bootstrap-typeahead.
Related Issues (20)
- Is this project actively maintained? HOT 2
- Suggest list is hover, after swipe the list HOT 1
- Suggestion: support array of objects as data source HOT 4
- Suggestion: Would like to see "state" added as a prop HOT 1
- Autofocus when component mounted or after refresh page HOT 2
- How it will work with typescript? HOT 2
- Sort Suggestions HOT 2
- Selected value lost on route change and back to the main typeahead page HOT 5
- Invalid prop: custom validator check failed for prop "serializer".
- Migration from vue-strap HOT 1
- v-model does not show the value of the attribute loaded in created() or mounted() HOT 2
- THIS PROJECT ABANDONED ..! ..? HOT 2
- ReferenceError: Can't find variable: regeneratorRuntime
- No disable HOT 2
- blur-attribut HOT 1
- v-model= null throws error Cannot read property 'normalize' of null
- Typo error
- Scroll bar is not working when we use it in a modal popup.
- Use keyboard arrow up/down to move through candidate and Enter to select
- Error When I try to use Number in Search
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-bootstrap-typeahead.