Alex
Alex

Reputation: 8072

jquery ui autocomplete without filter

I need to show user all autocomplete choices, no matter what text he already wrote in the field? Maybe i need some other plugin?

$('#addressSearch').autocomplete("search", "");

That doesn't work.

Upvotes: 4

Views: 1937

Answers (2)

Andrew Whitaker
Andrew Whitaker

Reputation: 126042

There are two scenarios:

  1. You're using a local data source. This is easy to accomplish in that case:

    var src = ['JavaScript', 'C++', 'C#', 'Java', 'COBOL'];
    $("#auto").autocomplete({
        source: function (request, response) {
            response(src);
        }
    });
    
  2. You're using a remote data source.

    $("#auto").autocomplete({
        source: function (request, response) {
            // Make AJAX call, but don't filter the results on the server.
            $.get("/foo", function (results) {
                response(results);
            });
        }
    });
    

Either way you need to pass a function to the source argument and avoid filtering the results.

Here's an example with a local data source: http://jsfiddle.net/andrewwhitaker/e9t5Y/

Upvotes: 8

mre666
mre666

Reputation: 336

You can set the minLength option to 0, then it should work.

Upvotes: 0

Related Questions