autocomplete icon indicating copy to clipboard operation
autocomplete copied to clipboard

Highlighting

Open kobykorman opened this issue 10 years ago • 6 comments

Hey guys,

In the original twitter typeahead there was the highlight option, with algolia's implementation we have to access suggestion._highlightResult..., but what if I'm using the plugin with my own ajax calls like I used to do with twitter typahead, instead of the Algolia service? Is there a highlighting solution I'm not aware of?

kobykorman avatar Apr 19 '16 18:04 kobykorman

Hi @legshooter,

yes indeed we removed it because our API was already doing the highlight. But your use-case is definitely legit, I'll try to restore such a feature. In the meantime, you can probably hack a .replace(/\bQUERY_WORD/g, '<em>QUERY_WORD</em>') for every word of your query.

redox avatar Apr 19 '16 22:04 redox

Hi @redox,

My workaround currently looks like this:

suggestion: function (suggestion) {
    var query = $('.search').autocomplete('val');
    var regExp = new RegExp('(' + query + ')', 'giu');
    return suggestion.name.replace(regExp, '<span class="highlight">$1</span>');
},

Takes care of case in/sensitivity etc.

Eagerly waiting for the official patch.

Thanks a lot for the pro tip and quick response, and keep being awesome!

kobykorman avatar Apr 19 '16 23:04 kobykorman

+1, also miss this feature from typeahead.

ifeltsweet avatar Oct 19 '16 18:10 ifeltsweet

Thanks for getting back here, currently the workarou from @legshooter is the way to go

vvo avatar Oct 19 '16 20:10 vvo

Just wanted to say I came here for this exact reason. Thanks @legshooter

VictorioBerra avatar Feb 22 '19 15:02 VictorioBerra

Autocomplete v0 has been in low maintenance mode for a few years and we just released Autocomplete v1 so I'm closing this.

Resources

francoischalifour avatar May 04 '21 10:05 francoischalifour