Can Choices be configured to use serverside searching (type-a-head)? eg. Fetch 5 results from server when 3 characters or more are entered in the search field?
You need a searchable index. Its cheaper to pull all available choices in one call rather than making a call after every segment of letters.
I'm using an elasticsearch index for the obvious reasons. Can it be done?
Yeah you can use the instance.ajax() method from the api.
As far as I can determine it's not possible to query the server when the user has typed 3 characters or more are show the results from the server in Choices. The instance.ajax() method is only called when the component is initialised.
There is no method that directly covers your use case. Your solution will require a combination of custom code mixed with the methods provided by the choices api. To query the server seems like a custom solution Tied in the the instance.search() listener. Then once you get a response you initialized/reinitialize the options or the choices instance. But the main reason why there are no samples is because this is specific to your case. Choices requires a searchable index but if you dont have one until an action is taken then it maybe a difficult approach. Would agree that it would be great for the api to work with elastic search right out of the box.
Just seconding what @fernandoagarcia said. Choices is a client-side library so any server logic will need to handled yourself. You could make a debounced request within the search event.
Thanks, with your directions I've constructed a solution: Example
Most helpful comment
Thanks, with your directions I've constructed a solution: Example