I'm on the hunt for a JQuery autocomplete that will:
- Search partial matches
- Highlight all occurrences whereever they appear
- Allow multiple word
- Allow remote datasources (i.e. PHP filters database results based on querystring that dynamically updates with each keypress)
So for example
Search: "me wa home"
Returns: "show me the wa y to go home"
I'm having a terrible time trying to find something that can offer this, even though it is common expectation of a Google-style autocomplete.
The monkeypatch of jquery ui autocomplete ( jQueryUI: how can I custom-format the Autocomplete plug-in results? ) comes close, but doesn't seem to offer dynamic remote datasources.
I've also come close with the following script:
var termTemplate = "<span class='ui-autocomplete-term'>%s</span>";
$("#f input").autocomplete({
source: "livesearch.php",
open: function(e, ui) {
var origKeyword = $("#f input").val();
var acData = $(this).data('autocomplete');
acData.menu.element.find('a').each(function() {
var me = $(this);
var regex = new RegExp(acData.term, "gi");
me.html(me.text().replace(regex, function(matched) {
return termTemplate.replace('%s', matched);
}));
});
},
select: function(event, ui) {
var keyword = $("#f input").val();
$("#f input").val('');
window.location.href = 'MYURLHERE?VARIABLE=' + ui.item.value;
return false;
},
focus: function(event, ui) {
return false;
}
});
However, it doesn't handle highlighting multiple words separated by a space.
if anyone has any suggestions, I'd be hugely grateful.