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

Suggestion: method to call to programatically search for a and show suggestions #63

Closed
seiz opened this issue Feb 28, 2013 · 3 comments
Closed
Milestone

Comments

@seiz
Copy link

seiz commented Feb 28, 2013

Hi,

i'd appreciate a method i could call, so typeahead would init, pull in the defined json, do the search and present the results.

Currently i do this with a hack: $("input.typeahead").trigger("input");

Some background on why i'd find this useful:
im am trying to use typeahead.js not only for suggestions but for a complete search engine.
My goal is to offer the user suggestions while he types into the input field and then, once hits the return key, i'll load a searchresults page and display a complete list of all matches. The search results page pre populates the input field with from a parameter in the query string, wires the field up with .typeahead and would then need to call a method so typeahead will do its magic and display the results (which i reformat with jquery so they'll not be attached to the input field any longer).

@jharding
Copy link
Contributor

jharding commented Mar 1, 2013

I've been kicking around the idea of adding a plugin method to retrieve suggestions from the datasets programmatically. Would something like the following support your use case:

// initialize the typeahead
$('.typeahead').typeahead({ /* options */ });

// after something happens and you want to retrieve the suggestions
// for a arbitrary query programmatically 
$('.typeahead').typeahead('getSuggestions', query, function(suggestions) {
  // do what you want with the suggestions here
});

@seiz
Copy link
Author

seiz commented Mar 1, 2013

That'd be awesome and much cleaner for the use case i described. Thanks!

Still, being able to tell the input to update and show results would probably come in handy from time to time, so i hope $("input.typeahead").trigger("input"); won't go away anytime soon.

@jharding
Copy link
Contributor

I think #159 resolves this issue. Please correct me if I'm wrong.

@jharding jharding closed this as completed Apr 1, 2013
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