jQuery UI.Autocomplete search method does not close result list
I am using jQuery v1.4.4 and jQuery UI 1.8.10. I have an AutoComplete on a text field which works fine when the user types in some text, the results are displayed. At this point the user can click outside of the results or press 'Esc' to close the result list.
If I use the Search Method to programmatically start a search, the results are shown as well, but the ESC button or c开发者_开发百科licking outside of the result box does not close the results.
What am I missing here?
Html:
<input id="txtTest" />
<input type="button" id="btnGo" value="Go" />
JavaScript:
var availableTags = [
"ActionScript",
"Java",
"Java 6",
"JavaScript",
"Scheme"
];
$("#txtTest").autocomplete({ source: availableTags });
$("#btnGo").click(function() { $("#txtTest").autocomplete("search", "j"); })
The issue is that the ESC/click to close only registers when the input has focus. What you could do is call focus
on the autocomplete after programtically opening it:
$("#btnGo").click(function() { $("#txtTest").autocomplete("search", "j").focus(); })
Here is a working example:
http://jsfiddle.net/magicaj/NtPnm/1/
精彩评论