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

change suggestion template depending on search query? #1197

Open
bkdotcom opened this issue Apr 27, 2015 · 3 comments
Open

change suggestion template depending on search query? #1197

bkdotcom opened this issue Apr 27, 2015 · 3 comments

Comments

@bkdotcom
Copy link

scenario: customer search autocomplete...
can search by name, email, phone, and a few other fields

typically Id like the suggestion template to simply be "name / email"

but if there's a phone-# match, I'd like to display phone number as well

reasonable? possible?

@jharding
Copy link
Contributor

First, if you wanted to do this right now, the only way I could think of would be to include some logic in your precompiled template that detects whether or not the query (available as _query within the context of the precompiled template) is a phone number and if so, render the phone number. Depending on what you're using for templating, this may not be feasible.

Second, I'm not sure what could be done to make this easier to do with typeahead.js. If you have any ideas, I'm all ears.

@bkdotcom
Copy link
Author

I'm using a function for the template
within the function, console.log(this) is an object

{
   empty: undefined,
   header: undefined,
   footer: undefined,
   suggestion:  function(obj)
} 

@jharding
Copy link
Contributor

Apologies, context was the wrong word. The argument passed to the precompiled template will contain _query e.g. obj._query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants