Jquery autocomplete doubt
$("#caller__MODULE_ID__").focus().autocomplete(userData, {
minChars: 0,
max:4,
width: "20%",
matchContains: true,
cacheLength: 0,
selectFirst: false,
autoFill: false,
formatMatch: function(row, i, max) {
return "<table class='tbl-ac' border='0' cellpadding='0' cellspacing='0'><tr><td>"+ userData[i].split(":")[0] + " <" + userData[i].split(":")[1] + "></td></tr></table>";
},
formatResult: function(row) {
开发者_Python百科 var rowString = row+"";
return rowString.split(":")[0];
}
});
Problem: Whenver I clear the text box , the first four entries of the autocomplete list are always displayed. How to eliminated them
I also noticed that when I hit a tab it clears. I tried a keypress event and that did not help too. See code below for keypress
$("#caller__MODULE_ID__").bind("keypress",function(event){
if($("#id").text()=="")
{
myEvent = jQuery.Event("keypress");
myEvent.keyCode= 9;
$("#caller__MODULE_ID__").trigger(myEvent);
}
});
PS: Tried on a firefox browser
You really need to take another look at the official documentation for autocomplete, the reason you are having problems is a lot of the added parameters that you are adding. (Including the formatMatch method you are calling, might I ask why exactly you are formatting it as a table?!)
All you really need to specify is the element to setup autocomplete on and the user-data, start there at the absolute raw start, and start adding back in your parameters. That will take you to the root cause of your error.
If you'd like me to debug a bit more for you please post your FULL code and I will jump through it to see what's causing your error.
Resource: http://docs.jquery.com/Plugins/autocomplete
Edit: (Add the bare bones of how this component works)
$("#caller__MODULE_ID__").autocomplete(userData);
精彩评论