Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom search function for jQuery UI Autocomplete

I'm using jQuery UI Autocomplete.

Is there a way to override its default search algorithm?

The changes I want to make are:

  • Prioritize words that start with the search term at the top of the suggested results.
  • Return a maximum of 5 results (instead of the default behavior, which is to return all matching results, potentially creating a really tall dropdown box).
like image 330
Emmett Avatar asked Nov 06 '22 08:11

Emmett


1 Answers

Normally, it all should be done in back-end. Your server-side script defines in what order and how many results will be returned.

Alternatively (if back-end is not under your control), you can specify function as source attribute. In this function you can query back-end and process results in whatever way your want. E.g., here's an example
http://jqueryui.com/demos/autocomplete/#multiple-remote

like image 136
Nikita Rybak Avatar answered Nov 09 '22 05:11

Nikita Rybak