jQuery's Autocomplete dropdown is not showing after upgrade to jQuery UI 1.10.3

强颜欢笑 提交于 2019-12-01 04:14:20

When using jQuery UI 1.10, you should not mess around with z-indexes (http://jqueryui.com/upgrade-guide/1.10/#removed-stack-option). Just make sure the autocomplete element is in the correct DOM order with: autocomplete.insertAfter(dialog.parent())

Example

 var autoComplete,
     dlg = $("#dialog"),
     input = $("#input");

 // initialize autocomplete
 input.autocomplete({
     ...
 });

 // get reference to autocomplete element
 autoComplete = input.autocomplete("widget");

 // init the dialog containing the input field
 dlg.dialog({
      ...
 });

 // move the autocomplete element after the dialog in the DOM
 autoComplete.insertAfter(dlg.parent());

After searching everywhere for this issue, I found that nobody had a solution to my problem as I could not produce any error messages and the code I showed was sound. After someone suggested I read the jQuery changelogs (which admittedly I hadn't), I found the bug in the jQuery as well as workaround:

In the jQuery UI 1.10.1 changelog, under the Autocomplete section it read:

Added: Use .ui-front instead of .zIndex() for the suggestions menu. (7d5fe02)

Following the link provided and looking through the jQuery code fix, gave me an idea: I performed my Autocomplete search, and then I moved the Modal Dialog to the side! That's when I noticed the Autocoplete dropdown suggestion menu was behind the Modal Dialog.

I fixed this by adding the following CSS rule:

ul.ui-autocomplete.ui-menu {
  z-index: 1000;
}

I have submitted a Bug ticket to jQuery, so I'm hoping it will be dealt with by 1.10.4 so that the workaround is no longer needed.

I hope this helps others too.

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