Example autocomplete with ajax call
-
Where do I see an example call with ajax?
My goal is a similar functionality with jQuery select2 and here you do not talk much http://beta.quasar-framework.org/components/autocomplete.html -
Register your search callback on to the autocomplete like so
@search="handleSearch"
.
The handle search function gets passed two parametersterms
anddone
.
Terms is the currently entered query and done a callback method to signal that the search has been performed.
Basically the handleSearch function looks like this:handleSearch (terms, done) { // Perform your search request SearchApi.search(terms) .then(response => { // Transform the response to an array defined in the autocomplete docs let results = transformSearch(response) // Call done and pass the result set done(results) }) }
-
Because currently, I have another issue with QAutocomplete, I posted a complete example in this Github issue:
https://github.com/quasarframework/quasar/issues/779#issuecomment-320902800This uses Axios and an Alogolia API endpoint to fetch countries.
-
I was able to list the api data, it worked very well, but little freedom to customize the layout of the item list.
Good thing I could do a template for the results. -
@a47ae
I added in the array an ID field, and did something like
<q-autocomplete @selected=“mySelected” />mySelected (item) { let vm = this vm.address.countryCode = item.id }
-
@lucianoreis Sadly I can not use the
@selected
event because I render multiple of these inputs in av-for
loop, so I do not know to which input the event belongs. -
This post is deleted! -
This post is deleted! -
copied from https://vuejs.org/v2/guide/events.html
Sometimes we also need to access the original DOM event in an inline statement handler. You can pass it into a method using the special $event variable:
<button v-on:click="warn('Form cannot be submitted yet.', $event)"> Submit </button>
methods: { warn: function (message, event) { // now we have access to the native event if (event) event.preventDefault() alert(message) } }
-
and then you just want
event.target
-
@rstoenescu this question/comment ( http://forum.quasar-framework.org/post/3412 ) keeps popping up about various vue-events defined in quasar docs, maybe this snippet from Vue docs should be integrated in quasar docs somehow ?
-
@a47ae Are you able to give some direction on how to enhance your example at https://github.com/quasarframework/quasar/issues/779#issuecomment-320902800 to enable infinite scroll of results . e.g. return 10 results at a time as the results are scrolled by the user?