Theia installation has been updated - September 10, 2011
« May 2012
S M T W T F S
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Theia
Activate jQuery autocomplete on focus « home
icon
posted on 20:29 - 13 January 2011 | posted by Lev
last modified on 20:31 - 13 January 2011 | last modified by Lev
I'm kind of surprised it took a little researching to get something this simple working as expected, but it seems as though jQuery's autocomplete UI feature won't automatically show you the default options (even if minLength is set to 0) unless the user hits some key in the field (even if focused).
 
I did some research and at first this was the best I found:
 
 
Unfortunately, this approach seems to have a caveat (at least for me on jQuery UI 1.8.7) - it only works the first time you place focus on the field. Oddly enough, the trigger is actually happening each subsequent time the field is focused, the auto-complete tool only pops up the first time.
 
Without rambling on too much, I'll show you what I came up with which works flawlessly each and every time the field is focused:
 
JAVASCRIPT CODE
    $('selector').autocomplete
        ({
        minLength: 0,
        source: function (t, r)
            {
            // get list here
            }
        })
    .focus
        (
        function()
            {
            if (this.value == "")
                {
                $(this).autocomplete('search', '');
                }
            }
        );
 
I hope this helps someone! :)
tags
  • 5
post reply
genial
quote
posted by: guest 186.162.28.46 · date: 20:38 - 18 May 2012
thanks
Perfect
quote
posted by: guest 202.160.118.225 · date: 22:25 - 29 February 2012
Exactly what I was looking for, cheers!
works
quote
posted by: guest 85.23.204.16 · date: 12:06 - 21 September 2011
great
It helped me very much.
quote
posted by: guest 217.92.109.222 · date: 16:06 - 05 August 2011
This was exactly what I was looking for.
Thank you so much for making my work easier.
Thanks
quote
posted by: guest 137.122.14.20 · date: 21:22 - 13 July 2011
That was exactly what I was looking for. It works great.
untitled
quote
posted by: guest 96.245.82.106 · date: 4:18 - 28 February 2011
thanks!
Bookmark item @
bookmarkbookmarkbookmarkbookmarkbookmark