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

[Request] Autocomplete extra parameter for server-side search #995

Closed
dmig opened this issue Oct 13, 2017 · 3 comments
Closed

[Request] Autocomplete extra parameter for server-side search #995

dmig opened this issue Oct 13, 2017 · 3 comments

Comments

@dmig
Copy link

dmig commented Oct 13, 2017

Right now @search handler of QAutocomplete receives only 2 parameters: search term and done callback.
I faced a situation, where I want to use one handler for multiple Autocomplete fields. The only thing I miss -- is the way to pass parameter to distinguish these fields.

E.g.:

<template>
  <q-input>
    <q-autocomplete @search="search" extra="field-name"/>
  </q-input>
</template>

<script>
// ...
search (term, done, extra) {
  this.$http.get('/api/autocomplete/mytable/'+extra+'/'+term).then(response => {
    done(response.data)
  }, err => { done([]) })
}
// ...
@Mohanrau
Copy link

@dmig you can pass extra like this

search (terms, done) {
        let query = {
          country_id: this.filterData.countryID,
          category_id: this.filterData.categoryID,
          text: terms
        }
        this.getProductSearchAction(query).then(res => {
          done(this.productSearchData.list)
        })
      },

@dmig
Copy link
Author

dmig commented Oct 20, 2017

@Mohanrau I need to pass extra data from component declaration, so your solution won't help.
Currenly I solved it like this:

<template>
...
<q-autocomplete :min-characters="2" :max-results="10" @search="search_a" />
...
<q-autocomplete :min-characters="2" :max-results="10" @search="search_b" />
...
<q-autocomplete :min-characters="2" :max-results="10" @search="search_c" />
...
</template>
<script>
// ...
let search_methods = {};
['a', 'b', 'c'].forEach(n => {
  search_methods['search_' + n] = (term, done) => {
    Vue.http.get('/api/endpoint/{field}', {params: {term, field: n}})
      .then(response => done(response.data), err => {
        console.error(err)
        done([])
      })
  }
})
// ...
  methods: {
  // ...
    ...search_methods
  // ...
  }
// ...
</script>

Vue object as 3rd parameter to search handler would also help.

@rstoenescu
Copy link
Member

<template>
  <q-input>
    <q-autocomplete @search="(terms, done) => mySearch(terms, done, 'field-name')" />
    <!-- mySearch (terms, done, extra) -->
  </q-input>
</template>

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