Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 443
Alex Avatar asked Feb 22 '23 21:02

Alex


1 Answers

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/

like image 118
Andrew Whitaker Avatar answered Feb 25 '23 13:02

Andrew Whitaker