Show options upon initial focus #90
-
I have the following use case:
I see in the docs how to prefetch, but I don't see any way to get the list of options to appear without typing at least one character in. If you use Google or Github's search feature, you'll see it is common to show suggestions without requiring the user to type anything in. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
@ericraider33 Hello, it is possible to display a list of default suggestions. For your use case, I'd suggest storing the prefetched items in the localStorage and then later reusing the same in the "empty" template. Something like this: typeahead({
input: document.querySelector('.myInput'),
source: {
prefetch: {
url: 'https://your-endpoint',
process: (items) => {
localStorage.setItem('users', JSON.stringify(items));
},
},
},
templates: {
empty: (resultSet) => {
return JSON.parse(localStorage.getItem('users'));
,}
}
}); |
Beta Was this translation helpful? Give feedback.
-
Hello. I'm testing to do that using the "empty" template, but, the resultSet received by empty has a limit = 5. Thanks. |
Beta Was this translation helpful? Give feedback.
@ericraider33 Hello, it is possible to display a list of default suggestions.
There is an example on the playground. The first example found here -> https://typeahead.digitalfortress.tech/#playground?id=colors-example
For your use case, I'd suggest storing the prefetched items in the localStorage and then later reusing the same in the "empty" template.
Something like this: