Comments (1)
@bencarter78 Scratched my head on this one for some time. Here's what worked:
export default {
extends: VueTypeahead,
data () {
return {
src: '/guided_search/keyword_search',
limit: 5,
minChars: 3,
showItems: true // for some reason, directly manipulating the items array is buggy; i.e. items = [] is not reliable
}
},
methods: {
doUpdate(event) {
this.showItems = true
this.update()
},
onHit(item) {
this.query = item
$("input[name='disease']").val(this.query) // firefox needs this ¯\_(ツ)_/¯
this.softReset()
},
softReset() {
this.loading = false
this.showItems = false
}
}
}
and in the template:
<input type="text"
name="disease"
:class="{'Typeahead__input': true}"
placeholder="Example: Leukemia"
autocomplete="off"
v-model="query"
v-validate="'required'"
@keydown.down="down"
@keydown.up="up"
@keydown.enter="hit"
@keydown.esc="reset"
@blur="softReset"
@input="doUpdate"/>
<ul v-show="hasItems && showItems">
...
</ul>
In my case I wanted the query to stay in the input on blur, even if no results matched. Clearing out the items via items = []
was giving me mixed results. I would type 3 characters (the default to trigger the data to load) and according to the Chrome vue inspector, I could see the items var get populated with a few results. In softReset() I was calling items = []
. Logging that in the console, items was empty. However, in the vue inspector it was still populated and the dropdown with options was still appearing. Not sure what's going on there; something with data and extends
maybe? I ended up adding showItems
to data as a workaround.
It would be nice to have a "selecting item populates the input box" as a core feature as this is a pretty common use case. Would be happy to submit a pull req, but my solution above is a bit hacky and I'm stumped why manipulating the items array isn't working.
I should also mention that this does not fix the update event from firing on blur - this could be the expected Vue behavior, but I'm not certain.
from vue-typeahead.
Related Issues (20)
- items not always populated with latest results HOT 1
- trap the delete event on typeahead component HOT 1
- Add delay function HOT 1
- Current selection should be reset inside reset()
- How I can cancel the previous search you have added?
- How I can cancel the previous search you have added?
- How I can cancel the previous search you have added? HOT 2
- Laravel Mix --production issue
- selectFirst
- Set data from objects array? HOT 3
- Different v-model?
- Uncaught ReferenceError: _vue is not defined HOT 1
- Make width of list responsive
- Prevent auto submit form in the onHit method HOT 2
- Is there a way to provide source as JSON file HOT 1
- Debounce event
- still active?
- Example of datasource
- compatible with nuxt?
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-typeahead.