views:

686

answers:

3

I'm using the Jörn Zaefferer's jQuery autocomplete plugin which works great, except for a small bug: if a user begins typing in one field where the autocomplete is attached to, but then while the suggest is still showing they click on another input field, the cursor returns back to the field with the autocomplete.

Are there any solutions to this, or is it pretty much the way works? I noticed that the jQuery UI autocomplete does the same thing.

+2  A: 

I've been kind enough to look at the code for you, uncomment this line:

// TODO provide option to avoid setting focus again after selection? useful for cleanup-on-focus
input.focus();

In jquery.autocomplete.js line 583.

Luca Matteis
Heh, like this answer better than the first :)
Darryl Hein
Actually, it's a combo of your previous answer and this one.
Darryl Hein
+1  A: 

The fix is:

Comment out lines 308-310 of the unpacked version:

//if (wasVisible)
    // position cursor at end of input field
    //$.Autocompleter.Selection(input, input.value.length, input.value.length);

And from Luca's post, comment out line 510:

//input.focus();

These both need to be commented out to make it work properly.

Darryl Hein
A: 

How about if the user uses the Enter-key or the TAB-key? How can I stop the plugin from setting focus in the input field then? You got that to work as well, or only when the user used the mouse to choose from the drop down?

Kim Andersen