jQueryUI autocomplete not working with dialog and zIndex

前端 未结 14 1278
孤独总比滥情好
孤独总比滥情好 2021-02-05 00:51

I ran into an interesting issue with jQueryUI autocomplete in a dialog box.

My dialog HTML looks like this:

14条回答
  •  青春惊慌失措
    2021-02-05 00:57

    Changing the z-index only works the first time the drop-down is opened, once closed, the dialog window realizes it has been "tricked" and upgrades its z-index.

    Also for me changing the order of creation of the dialog and auto-complete really was a hassle (think big web site, tons of pages) but by chance I had my own openPopup function that wrapped openedDialog. So I came up with the following hack

    $("#dialog").dialog({ focus: function () {
        var dialogIndex = parseInt($(this).parent().css("z-index"), 10);
        $(this).find(".ui-autocomplete-input").each(function (i, obj) {
            $(obj).autocomplete("widget").css("z-index", dialogIndex + 1)
        });
    });
    

    Each time the dialog has the focus i.e. on 1st opening and when the auto-complete is closed, each auto-complete list's z-index gets updated.

提交回复
热议问题