jQuery autocomplete “response” event

人盡茶涼 提交于 2019-12-05 03:44:48

This callback-method arrived with the new jquery-ui. I could not get this to work, but after i updated from 1.8.20 to 1.9.2 the callback fires just as it is supposed to.

Hope it helps!

Assuming that all of your code is correct, you may need to upgrade your version of jQuery UI (and the corresponding jQuery as well). This is because although the documentation you were looking at says "Autocomplete widget version added: 1.8," the response event was not added until 1.9 (See the jQuery 1.9 Upgrade Guide: Response Event) This also means that you will not be able to "Bind an event listener to the autocompleteresponse event" as the guide states.

Once you upgrade to a jQuery and jQuery UI version which supports the autocomplete response event, this code will work as expected.

As a tip to anyone new to this event, keep in mind that if you modify the data, you need to include both the value and label properties for each item you want to add, even if your source data was just an array of values. This is because once the content gets into this event, it has already been 'normalized' (that is, the label has been pared with a value).

So if you want to add "Other" to the results returned, your response event would look like:

response: function (e, ui) {
  ui.content.push(
    {label:"Other", value:"Option"}
  );
}

This will add an "Other" option to every list, which will have a input value of "Option."

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!