0

I want to display the entire autocomplete list on click of a button. I have tried the below code but it is not working.

 $("#<%= btnCompanyList.ClientID%>").live('click', function (e) {
        alert("hi");
        $("#txtDefaultCompany").autocomplete({
                    source: function (request, response) {
                        $.ajax({
                            url: "AutoComplete.asmx/GetCompanyname",
                            data: "{'prefixText':" + JSON.stringify(request.term) + "}",
                            dataType: "json",
                            type: "POST",
                            contentType: "application/json; charset=utf-8",
                            dataFilter: function (data) { return data; },
                            success: function (data) {
                                alert(data.d);
                                response($.map(data.d, function (item) {
                                    return {
                                        label: item.company_name,
                                        value: item.company_branch
                                    }
                                }))
                            }
                        });
                    },
                    minLength:0

                });

    });

On button click the textbox might be empty. But i want to display the entire list. Any ideas or suggestions please.

Thanks,

asifa
  • 771
  • 1
  • 28
  • 63

2 Answers2

0

You'll need to call .search on the autocomplete object as per the doco

Hope this helps...

leon.io
  • 2,779
  • 1
  • 18
  • 26
0

Simple,

You have an example here: on jsfiddle

But if you want to use it with an ajax call, then simply add to ajax "success:" function the following:

$(yourtxt).autocomplete({
    source: JSON.parse(resultData),
    minLength: 0
}).on("focus", function () {
    $(this).autocomplete("search", '');
});

// set product combobox source
$(yourtxt).autocomplete('search', '');
pushkin
  • 9,575
  • 15
  • 51
  • 95
Pacurar Stefan
  • 235
  • 4
  • 9