When I use jQuery UI autocomplete, I need the tab key to fill the search box with the first element in the autocomplete results, then specify a space, then allow the user to continue to enter text.
<div class="ui-widget"> <form id="searchbox" method="GET" action="http://duckduckgo.com/"> <input id="search" type="text" name="q"> <input id="submit" type="submit" value="Search"> </form> </div> <script> var tabKey = 9; $('#search').autocomplete({ source: [ 'this', 'that', 'foobar' ], delay: 0, selectFirst: true, select: function(event, ui) { if (event.keyCode == tabKey) { $('#search').focus().select(); } } }); </script>
In other words, in the above example, if someone typed "th", they would see "this" and "that" in the autocomplete options. The βOnβ tab will add βthisβ (note the spacebar) to the input, and focus will remain on the input.
Can someone give me a pointer to what I missed? I don't know Javascript very well, so little words are good :)
And perhaps more useful information (jquery 1.7.2) from the HEAD section:
<script src="js/jquery-latest.js"></script> <script src="js/jquery-ui-1.8.20.custom.min.js"></script> <link rel="stylesheet" type="text/css" href="css/jquery-ui-1.8.20.custom.css" />
Edit: It seems that autoFocus: true will get me there. Now, if I can just figure out how to focus on the input window.
jquery jquery-ui autocomplete
Ovid
source share