I’m using the jQuery UI Autocomplete plug-in. Is there a way to highlight search character sequence in drop-down results?
For example, if I have “foo bar” as data and I type "foo" I’ll get “foo bar” in the drop-down, like this:
I’m using the jQuery UI Autocomplete plug-in. Is there a way to highlight search character sequence in drop-down results?
For example, if I have “foo bar” as data and I type "foo" I’ll get “foo bar” in the drop-down, like this:
Here it goes, a functional full example:
Hope this helps
this also works:
a combination of @Jörn Zaefferer and @Cheeso's responses.
Take a look at the combobox demo, it includes result highlighting: http://jqueryui.com/demos/autocomplete/#combobox
The regex in use there also deals with html results.
Super helpful. Thank you. +1.
Here is a light version that sorts on "String must begin with the term":
you can use folowing code:
lib:
and logic:
it creates custom widget that can override
_renderItem
without overwriting_renderItem
of original plugin prototype.in my example also used original render function to some simplify code
it's important thing if you want to use plugin in different places with different view of autocomplete and don't want to break your code.
If you instead use the 3rd party plugin, it has a highlight option: http://docs.jquery.com/Plugins/Autocomplete/autocomplete#url_or_dataoptions
(see the Options tab)