I am trying to implement something like google instant seach that displays possible searches as you type in the text box.
So far I got the results as json string and jquery autocomplete display them perfectly. Now I want to show all the results that has search keywords.
Like say for example, if search keys are “foo bar” and my result has “foo fun bar”; now the “foo” and “bar” keys are contained in the result but current autocomplete plugin doesn’t display it.
Is there a way to modify the plugin to achieve this?
You’ll need to modify the default behavior of the autocomplete widget’s filter function to split the text box value into individual tokens and search the source object on each token.
You can download the jQuery UI source here. Have a look at jquery.ui.autocomplete.js line 422 for the filter function you’ll need to modify. You’ll notice that it returns a test of a regular expression to see if the value object’s label member, value member, or the value object itself matches the regular expression. You’d have to instead aggregate the test results on every string in the array returned by a call to .split() on a string element derived from one of those three sources.
If you’d like to minify your modified autocomplete code, use Google’s Closure Compiler Service.