autocomplete: allow function for asynchronous completions
See original GitHub issueIt would be nice if a function could be specified to provide completions asynchronously. This could be useful for datasets that cannot be located completely on the client and must be fetched partially from the server, as in the following example:
$("input").autocomplete({
fetch: function (val, callback) {
fetch("/api/complete?query=" + encodeURIComponent(val))
.then(function (response) {
response.json().then(function (json) {
callback(null, json);
});
});
}
});
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:7
Top Results From Across the Web
AutoComplete - Node-RED
This allows the function to do asynchronous work to generate the completions. The returns list of completions must be an array of objects...
Read more >Example: Autocompletion - CodeMirror
Providing Completions Sources may run asynchronously by returning a promise. The easiest way to connect a completion source to an editor is to...
Read more >Completions - Sublime Text
Asynchronous completions can be provided by on_query_completions() returning a sublime.CompletionList object. Completion details, including kind metadata, are ...
Read more >Type less, code more with IntelliCode completions
In Visual Studio 2022 Preview 1 you can automatically complete code, up to a whole line at a time! Check out the video...
Read more >c# - Autocomplete Method Brackets - Stack Overflow
When doing autocomplete, instead of just hitting ENTER, you can instead press the key combination "Shift + (" and it will autocomplete and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
By the way, this is how you would use the approach above for querying GitHub:
“Data model” definition:
Initialization:
Markup:
What I was thinking of is a client provided hook around the folowing point in js/forms.js#L319…327:
such that the hook gets called with
val
and is in charge of generating the dataset for that text, maybe asynchronously, which then gets rendered intoli
tags.Also, I believe the code could be improved by extracting the different concerns to configurable functions, namely
completion
,rendering
andvalue extraction
, making the component agnostic of data format and capable of supporting different layouts in the suggestions panel.Like in the following code (it’s just a draft, I need to test it yet):
It may look quite complex, but there are a few improvements here:
The last one is what this issue is about and it’s very useful for datasets that won’t fit in the client unless pre-filtered server-side.
It may make sense not to expose the data model to the client; it’s a material design library after all. But having it makes it easy to support the different designsø.