Reputation: 4038
I'm trying to get a jQuery autocomplete instance to open on the textbox focus, and fetch data from the remote source. An approximation of my attempt is shown here:
The problem with this is that you'll note the extra call to the textbox focus method when you select a value from the dropdown. I can't figure out a way to prevent this extra call, as it is interfering with the functionality.
Is there a better way to do what I'm trying to achieve?
Upvotes: 2
Views: 4399
Reputation: 126052
Here's a solution that's not too hacky:
$('#tags').focus(function() {
/* Only search if the autocomplete menu is hidden: */
if ($("ul.ui-autocomplete").is(":hidden")) {
$(this).autocomplete('search', '');
}
});
Updated example: http://jsfiddle.net/9x3hu/
If you're curious, here's the line that's causing you grief. Looks like after you select an item, the input
targeted by the widget is focused automatically.
This might seem odd, but it probably has to do with using the UP
and DOWN
arrows to navigate the dropdown list. In that case, you'd want focus to return to the input
.
Upvotes: 6
Reputation: 3707
is that because you use append..
try this:
$('#status').html('<br />getting values...');
Upvotes: 0