I’ve found a number of examples that show how to highlight multiple matches e.g. if i type in “art design”, I would want it to highlight it as “art and design degree”
The following example (albeit with a static array) is what I’m after:
http://jsfiddle.net/Q4jy9/1/
However, I don’t know how to get this working for a remote php datasource.
Below is the current code I’m using. Each keypress sends the term to my php and that selects matches from the database.
Is there a way I can either change the script below to allow highlighting of multiple words/matches, or change the script in the above link to work with an external datasource?
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;
}
});
With the help of tborychowski, I think we have a working solution 🙂