I'm using the jQuery Autocomplete plugin, but I'm having some problems with the result highlighting. When a match is found, but the entered keyword contains spaces, there's no highlighting. Example:
search = "foo", result = "foo bar", displayed = "foo bar"
search = "foo ba", result = "foo bar", displayed = "foo bar"
So, I'm trying to fix this using the highlight option of the autocomplete function where you can use a function to do some custom stuff with the results. Currently I have this:
$('.autocomplete').autocomplete('getmatch.php', {
highlight: function(match, keywords) {
keywords = keywords.split(' ').join('|');
return match.replace(/(get|keywords|here)/gi,'<b>$1</b>');
}
});
The replace function replaces all the matched words in the string with a bold version, that works. However, I don't know how to get the keywords into that function. I though I'd split them, and then join them with a '|', so "foo bar" ends up like "foo|bar". But something like this doesn't seem to work:
return match.replace(/(keywords)/gi,'<b>$1</b>'); // seen as text, I think
return match.replace('/'+(keywords)+'/gi','<b>$1</b>'); // nothing either
Any ideas?