Is it possible to add some html to jquery autocomplete ui item?
For example, I’d like to add <strong></strong> tags to autocomplete resulting item label: item['name']. I’ve tried to do label: '<strong>'+item['name']+'</strong>, but it is applied as text, not HTML.
$('input[name="customer"]').catcomplete({
delay: 0,
source: function(request, response) {
$.ajax({
url: 'index.php?route=sale/customer/autocompletefilter_name=' + encodeURIComponent(request.term),
dataType: 'json',
success: function(json) {
response($.map(json, function(item) {
return {
category: item['customer_group'],
label: item['name'],
customer : item['name'],
value: item['customer_id'],
customer_group_id: item['customer_group_id'],
firstname: item['firstname'],
lastname: item['lastname'],
email: item['email'],
telephone: item['telephone'],
fax: item['fax'],
address: item['address']
}
}));
}
});
},
select: function(event, ui) {
//some actions on select
}
});
Thnak you.
Check out Scott Gonzales’ autocomplete HTML extension –
https://github.com/scottgonzalez/jquery-ui-extensions/blob/master/src/autocomplete/jquery.ui.autocomplete.html.js. It’ll allow you to pass in HTML for the label option.
Example – http://jsfiddle.net/eay3d/1/
Edit 09/22/2013: Source link repaired, but no longer maintained.