jquery ui autocomplete: clicking on list does nothing
i use jquery ui autocomplete and took the example from this link .
this is my modification:
$(function() {
$(".autocomplete").live('keyup.autocomplete', function() {
$(".autocomplete").autocomplete({
source: function(request, response) {
$.ajax({
'url': "http://localhost/project/index.php/product/search_data/",
'data': { 'txt_product_name': $('#txt_product_name').val()},
'dataType': "json",
'type': "POST",
'success': function(data){
response(data);
}
})
},
minLength: 2,
focus: function( event, ui ) {
$(".txt_product_id").val(ui.item.product_id);
return false;
},
select: function( event, ui ) {
$( ".txt_product_id" ).val(ui.ite开发者_JS百科m.product_id);
$( ".txt_product_code" ).val(ui.item.product_code);
$( ".txt_product_name" ).val(ui.item.product_name);
return false;
}
}).data("autocomplete" )._renderItem = function( ul, item ) {
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a>" + item.product_code + "<br>" + item.product_name + "</a>" )
.appendTo(ul);
};
})
});
the code works fine. and for my own purpose, i revise _renderItem
so the result will be displayed in colums:
data("autocomplete" )._renderItem = function(table, item) {
return $( "<tr></tr>" )
.data("item.autocomplete", item)
.append("<td><a>" + item.product_code + "</a></td><td><a>" + item.product_name + "</a></td>")
.appendTo(table);
};
the suggestion list shows up everytime i type my entries. but unlike before, clicking on the list does nothing to txt_product_id
, txt_product_code
and txt_product_name
.
what should i do? any suggestions will be welcomed.
thanks in advance.
精彩评论