How to display jQuery UI autocomplete list on focus event

At the time of working with jQuery UI autocomplete, sometimes we’re getting a requirement to display list on focus. Means the autocomplete list would be shown on focusing the input box. Once start entering in the input field, autocomplete list would be filtered as per the entered character.

focus() event of jQuery UI autocomplete lets you to show all options before start entering. You need to add the .focus(function(){}) with your existing jQuery UI autocomplete code.

$(function() {
    $( "#searchInput" ).autocomplete({
        source: "searchList.php",
        minLength: 0
    }).focus(function(){
        if (this.value == ""){
            $(this).autocomplete("search");
        }
    });
});

1 Comment

  1. 吳渡仁 Said...

Leave a reply

keyboard_double_arrow_up