Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery UI Autocomplete - Have the menu open when user clicks in the text box

I'm using this JQuery autocomplete widget.

How can I make it automatically open the menu when the user clicks in the text box? I want the user to see all the options.

like image 335
Greg Avatar asked Dec 06 '11 14:12

Greg


People also ask

How does AutoComplete work in jQuery?

In the process of searching a specific value, the jQuery UI autocomplete selection feature provides the user with some string suggestions for the input area which effectively saves time. The autocomplete select action is triggered when the user selects one of the options from the pre-populated list.

How can create AutoComplete search box in jQuery?

Syntax: $("TagId"). autocomplete({ source : itemList // List of Words. })

How do you find the value of AutoComplete?

The AutoComplete control supports strongly-typed HTML helpers represented by lambda expressions that have model or template passed into the View. So, you can get the selected value from view in the Controller part. To achieve this, create an AutocompleteFor control and bound the dataSource from controller part.

What is the function of AutoComplete?

AutoComplete helps you quickly insert functions and arguments while minimizing typing and syntax errors. The AutoComplete menu shows you available options based on context, and you choose what you want to insert into your formula.


2 Answers

You need to trigger the search event manually and set the minLength option on the widget to zero:

$("input").autocomplete({
    minLength: 0,
    /* other options */
}).on("focus", function () {
    $(this).autocomplete("search", "");
});

Working example: http://jsfiddle.net/9JmVu/

like image 151
Andrew Whitaker Avatar answered Nov 15 '22 03:11

Andrew Whitaker


I think I got it actually. If you set minLength to 0, and then trigger a search for "", it opens the menu.

      $(inputSelector).autocomplete(
              {
                  source: this.validConstructCodes,
                  minLength: 0,
                  autoFocus: true,
                  autoSelect: true
              });
      $(inputSelector).focus(function(event) {
        $(this).autocomplete( "search" , "" );
      });
like image 28
Greg Avatar answered Nov 15 '22 03:11

Greg