jQuery autocomplete UI - I'd like to start the search "onfocus" and immediately show the list of choices when the user tabs or clicks into the search field without the user having to type anything.
The default behavior seems to requires the user to enter a character or a down arrow to start the ball rolling and start the search and get the values even when I set the number of character required to zero.
$( "#contact" ).autocomplete({ source: 'remote.php', minLength: 0 });
thanks!
Try binding the
focus
with autocomplete.Check out my sample JSFiddle.
this solution not working for me, but this:
works good (source: jquery forum)
A bit more complicated than Emmett's answer, but...
Here it is:
I found that this code was a little cleaner and element specific.
This solution didn't exactly work for me because the autocomplete results box would pop back up once more after selecting the desired result. This was because the
.focus
method was executed before theclose:
event.Additionally, according to the code in that answer, once the box closed, it wouldn't open back up because the
closing
variable stayedtrue
due toclose:
being executed after.focus
.The following code resolved those two issues (note the variable
closing
is set to false in theclose:
event):JQUERY actually suggests this method
http://api.jqueryui.com/autocomplete/#method-search
basically you use minLength:0 and the focus event with a search for "".