Search code examples
jquery-uiautocomplete

jQuery AutoComplete Trigger Change Event


How do you trigger jQuery UI's AutoComplete change event handler programmatically?

Hookup

$("#CompanyList").autocomplete({ 
    source: context.companies, 
    change: handleCompanyChanged 
});

Misc Attempts Thus Far

$("#CompanyList").change();
$("#CompanyList").trigger("change");
$("#CompanyList").triggerHandler("change");

Based on other answers it should work:

How to trigger jQuery change event in code

jQuery Autocomplete and on change Problem

JQuery Autocomplete help

The change event fires as expected when I manually interact with the AutoComplete input via browser; however I would like to programmatically trigger the change event in some cases.

What am I missing?


Solution

  • Here you go. It's a little messy but it works.

    $(function () {  
      var companyList = $("#CompanyList").autocomplete({ 
          change: function() {
              alert('changed');
          }
       });
       companyList.autocomplete('option','change').call(companyList);
    });