模态 ui 对话框内的 jquery UI 自动完成 - 建议未显示?

发布于 2024-09-09 01:25:28 字数 585 浏览 2 评论 0原文

我正在 jquery ui 对话框中使用 jquery ui 自动完成小部件。当我输入搜索文本时,文本框缩进(ui-autocomplet-loading)但不显示任何建议。

var availableTags = ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl"];

$("#company").autocomplete({        
    source : availableTags ,
minLength: 2
});

company 是附加自动完成功能的文本框的 ID。

我认为这可能是 az 索引,所以我设置了这个:

.ui-autocomplete, .ui-menu, .ui-menu-item {  z-index: 1006; }

但它仍然不显示。我将自动完成功能放在“常规”页面中,效果很好。

我正在使用 jquery ui 版本 1.8.2。有什么想法去哪里看吗?

i am using the jquery ui autocomplete widget inside the jquery ui dialog. when i type in the search text, the textbox indents (ui-autocomplet-loading) but does not show any suggestions.

var availableTags = ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl"];

$("#company").autocomplete({        
    source : availableTags ,
minLength: 2
});

company is the id of the textbox to attach the autocomplete.

i thought it might be a z index so i set this:

.ui-autocomplete, .ui-menu, .ui-menu-item {  z-index: 1006; }

but it still does not show. i put the autocomplete in a 'regular' page and it works fine.

i am using jquery ui version 1.8.2. any ideas of where to look?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(19

放飞的风筝 2024-09-16 01:25:28

我在搜索同一问题时遇到了这个答案,但是没有一个解决方案正是我想要的。

使用 appendTo 工作了,有点...自动完成项目显示在它们应该出现的地方,但是它完全把我的对话框窗口变成了一堆未正确重新定位的 div 元素的乱码。

因此,在我自己的 css 文件中,我创建了以下内容:

ul.ui-autocomplete {
    z-index: 1100;
}

我确信 1100 有点过大,但我只是想安全一点。效果很好,符合KISS方法。

我正在使用 jQuery 1.9.2 和 jQueryUI 1.10.2。

I came across this answer when searching for this same issue, however none of the solutions were exactly what I wanted.

Using appendTo worked, sorta... The autocomplete items showed up where they were supposed to, however it completely threw my dialog window into a garbled mess of improperly repositioned div elements.

So in my own css file, I created the following:

ul.ui-autocomplete {
    z-index: 1100;
}

I'm sure 1100 is a little overkill, but I just wanted to play it safe. It works well and conforms with the K.I.S.S. method.

I'm using jQuery 1.9.2 with jQueryUI 1.10.2.

情深缘浅 2024-09-16 01:25:28

使用 jQuery UI 1.10 时,不应乱用 z 索引 (http: //jqueryui.com/upgrade-guide/1.10/#re​​moved-stack-option)。 appendTo 选项有效,但会将显示限制为对话框的高度。

要修复此问题:请确保自动完成元素处于正确的 DOM 顺序:autocomplete.insertAfter(dialog.parent())

示例

 var autoComplete,
     dlg = $("#copy_dialog"),
     input = $(".title", dlg);

 // 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());

<强>单击对话框后更新 z-index 问题

单击对话框后自动完成的 z-index 似乎发生了变化(如 MatteoC 报告)。下面的解决方法似乎可以解决此问题:

请参阅小提琴: https://jsfiddle.net/sv9L7cnr/

// initialize autocomplete
input.autocomplete({
    source: ...,
    open: function () {
        autoComplete.zIndex(dlg.zIndex()+1);
    }
});

When using jQuery UI 1.10, you should not mess around with z-indexes (http://jqueryui.com/upgrade-guide/1.10/#removed-stack-option). The appendTo option works, but will limit the display to the height of the dialog.

To fix it: make sure the autocomplete element is in the correct DOM order with: autocomplete.insertAfter(dialog.parent())

Example

 var autoComplete,
     dlg = $("#copy_dialog"),
     input = $(".title", dlg);

 // 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());

Update for z-index problem after dialog click

The z-index of the autocomplete seems to change after a click on the dialog (as reported by MatteoC). The workaround below seems to fix this:

See fiddle: https://jsfiddle.net/sv9L7cnr/

// initialize autocomplete
input.autocomplete({
    source: ...,
    open: function () {
        autoComplete.zIndex(dlg.zIndex()+1);
    }
});
旧时模样 2024-09-16 01:25:28

我在引导箱中解决了这个问题,如下所示:

$( "#company" ).autocomplete({       
    source : availableTags ,
    appendTo: "#exportOrder"
});

您只需将结果列表附加到您的表单中。

I solved it in bootbox like this:

$( "#company" ).autocomplete({       
    source : availableTags ,
    appendTo: "#exportOrder"
});

You only have to append the result list to your form.

£烟消云散 2024-09-16 01:25:28

在您的 autocomplete 实现中,添加 appendTo: "#search_modal",其中 search_modal 是模态框的 ID。

In your autocomplete implementation, add appendTo: "#search_modal", where search_modal is ID of your modal.

ぇ气 2024-09-16 01:25:28

对于同一对话框中的一个或多个自动完成:

// init the dialog containing the input field
 $("#dialog").dialog({
      ...
 });

// initialize autocomplete
 $('.autocomplete').autocomplete({        
      source: availableTags,
      minLength: 2
 }).each(function() {
      $(this).autocomplete("widget").insertAfter($("#dialog").parent());
 });

for one or multiples autocompletes in the same dialogbox:

// init the dialog containing the input field
 $("#dialog").dialog({
      ...
 });

// initialize autocomplete
 $('.autocomplete').autocomplete({        
      source: availableTags,
      minLength: 2
 }).each(function() {
      $(this).autocomplete("widget").insertAfter($("#dialog").parent());
 });
笔落惊风雨 2024-09-16 01:25:28
    $("#company").autocomplete({        
    source : availableTags ,
    appendTo : $('#divName')
    minLength: 2
});

注意:$('#divName') divName 将是模态体的名称。

例子:

<form id="exportOrder">
        <div class="input-group">
            <input type="text" id="accountReferenceSearch" placeholder="Type Account Reference to search..." class="form-control" style="width:500px">
        </div>
    </div>
</form>

self.AttachAutoComplete = function () {
                    $('#accountReferenceSearch').focus(function () {
                        $('#accountReferenceSearch').autocomplete({
                            source: function (request, response) {},
                            minLength: 2,
                            delay: 300,
                            appendTo: $("#exportOrder")
                        });
                    });
                }
    $("#company").autocomplete({        
    source : availableTags ,
    appendTo : $('#divName')
    minLength: 2
});

Note: $('#divName') divName will be the name of modal body.

EXAMPLE:

<form id="exportOrder">
        <div class="input-group">
            <input type="text" id="accountReferenceSearch" placeholder="Type Account Reference to search..." class="form-control" style="width:500px">
        </div>
    </div>
</form>

self.AttachAutoComplete = function () {
                    $('#accountReferenceSearch').focus(function () {
                        $('#accountReferenceSearch').autocomplete({
                            source: function (request, response) {},
                            minLength: 2,
                            delay: 300,
                            appendTo: $("#exportOrder")
                        });
                    });
                }
就像说晚安 2024-09-16 01:25:28

我遇到了同样的问题,当我想到:

始终在设置自动完成之前声明您的对话框。

我已经切换了它们,等等!

自动完成功能围绕您的目标输入进行配置。 Dialog 围绕您的目标容器创建新的标记和 CSS。我的选择出现在对话框后面或屏幕外。

I was experiencing the same problem, when it occurred to me:

Always declare your dialog BEFORE setting autocomplete.

I’ve switched them around, et voilà!

Autocomplete configure itself around the INPUT you target. Dialog creates new markup and CSS around the container you target. My choices where appearing behind the dialog, or off screen.

后eg是否自 2024-09-16 01:25:28

我解决了将属性 z-index:1500 添加到我的 div 中的问题
jquery.autocomplete.css 因为 Jquery UI 对话框将 z-index 放在
1000 和 1005

ul.auto-complete-list {
    list-style-type: none;
    margin: 0;
    padding: 0;
    position: absolute;
    z-index: 1500;
    max-height: 250px;
    overflow: auto;
}

I solved adding atribute z-index:1500 to my divs in
jquery.autocomplete.css because Jquery UI Dialog put z-index between
1000 and 1005

ul.auto-complete-list {
    list-style-type: none;
    margin: 0;
    padding: 0;
    position: absolute;
    z-index: 1500;
    max-height: 250px;
    overflow: auto;
}
哥,最终变帅啦 2024-09-16 01:25:28

我们有同样的问题。我们刚刚更新了 CSS,以便 z-index 足够高并且不能被覆盖:

.dropdown-menu {
  z-index: 9999 !important;
}

由于附加到 body 使 $window 的下拉子项成为您需要将所有下拉菜单设置为新的 z-index。

We had the same issue. We just updated our css so that z-index is high enough and cannot be overwritten:

.dropdown-menu {
  z-index: 9999 !important;
}

As append to body makes the dropdown child of $window you need to make all dropdown-menu to the new z-index.

过度放纵 2024-09-16 01:25:28

我最近也遇到了同样的问题。将其添加到我的 css 文件中为我解决了这个问题:

.ui-autocomplete-input, .ui-menu, .ui-menu-item {  z-index: 2006; }

我首先尝试了初始 z-index 值 1006,但这不起作用。增加价值对我有用。

I recently had the same issue. Adding this to my css-file solved it for me:

.ui-autocomplete-input, .ui-menu, .ui-menu-item {  z-index: 2006; }

I first tried your initial z-index value of 1006, but that didn't work. Increasing the value worked for me.

孤蝉 2024-09-16 01:25:28

我也有这个问题。我正在 UserFrosting 工作,它有 bootstrap 和 select2,但核心没有 jquery-ui 。我的自动完成功能位于模态弹出窗口内,其中脚本标记和 $(document).ready 位于模态表单的 html 之后。在追踪各种不存在的冲突并尝试将 select2 (v 4) 放入组合框之后,我回到了 css hack 并且这有效:

.ui-autocomplete {z-index: 1061 !important;}

我的环境是

  • UserFrosting 和 jquery 1-11.2
  • bootstrap-3.3.2,
  • bootstrap-modal
  • select2 v3.5.1
  • jquery-ui-1.11.4(dot-luv主题)

I had this problem also. I am working in UserFrosting which has bootstrap and select2, but doesn't have jquery-ui in the core. My autocomplete was inside a modal popup where the script tag and $(document).ready are after the html for the modal form. After chasing all kinds of nonexistent conflicts and trying to make select2 (v 4) into a combobox, I went back to the css hack and this worked:

.ui-autocomplete {z-index: 1061 !important;}

My environment is

  • UserFrosting with jquery 1-11.2
  • bootstrap-3.3.2,
  • bootstrap-modal
  • select2 v3.5.1
  • jquery-ui-1.11.4 (dot-luv theme)
标点 2024-09-16 01:25:28

我遇到了同样的问题,已通过添加以下样式解决:

.ui-autocomplete { position: absolute;  cursor: default;z-index:30!important;}  
.modal-dialog {pointer-events:auto !important;}

I was facing same issue , It has been resolved by adding bellow styles :

.ui-autocomplete { position: absolute;  cursor: default;z-index:30!important;}  
.modal-dialog {pointer-events:auto !important;}
孤云独去闲 2024-09-16 01:25:28

在我的例子中,在 css 中添加样式不起作用,但是在将 zIndex 属性精确添加到 jQuery ui 元素构造函数之后,它就像一个魅力一样。

In my case adding styles in css doesn't work, but after adding zIndex property exactly to jQuery ui element constructor, it works like a charm.

柒夜笙歌凉 2024-09-16 01:25:28

将以下方法添加到您的 javascript 中,并从 body 元素的 onload 事件中调用它:

//initialization
function init(){
    var autoSuggestion = document.getElementsByClassName('ui-autocomplete');
    if(autoSuggestion.length > 0){
        autoSuggestion[0].style.zIndex = 1051;
    }
}

它对我有用:) 我通过查看模式对话框的计算样式来了解它的 z-index 是什么来得到这个。因此,该函数所做的就是获取由 jquery 创建的自动建议框(通过它的类名之一,这对你来说可能不同,但想法仍然相同)并修改它的 css 以包含比 z-index 高 1 点的 z-index模态的 z 索引(1050)

Add the following method to your javascript and call it from the onload event of the body element:

//initialization
function init(){
    var autoSuggestion = document.getElementsByClassName('ui-autocomplete');
    if(autoSuggestion.length > 0){
        autoSuggestion[0].style.zIndex = 1051;
    }
}

It works for me :) I got this by looking at the computed style of the modal dialog to see what it's z-index was. So all the function does is grab the auto suggestion box that's created by jquery (by one of it's class names which may be different for you but the idea is still the same) and modify it's css to include a z-index 1 point higher than the z-index of the modal (which was 1050)

风吹雨成花 2024-09-16 01:25:28

这对我来说很有效:

ul.ui-front {
    z-index: 1100;
}

This did the trick for me:

ul.ui-front {
    z-index: 1100;
}
伊面 2024-09-16 01:25:28

Johann-S 的回答这里对我有用。

只需将 data-focus="false" 添加到调用模态的按钮或链接,这样

<button type="button" class="btn btn-primary" 
 data-toggle="modal" 
 data-focus="false"
data-target=".bd-example-modal-sm">Small modal</button>

您就不必弄乱 z 索引或覆盖 bootstrap 的强制焦点(它不会被调用)

Johann-S ' answer here worked for me.

simply add data-focus="false" to the button or link calling the modal like

<button type="button" class="btn btn-primary" 
 data-toggle="modal" 
 data-focus="false"
data-target=".bd-example-modal-sm">Small modal</button>

This way you don't have to mess with z-indexes or override bootstrap's enforce focus (it's not called)

掐死时间 2024-09-16 01:25:28

我遇到了同样的问题,但经过一番努力后,我使用 Firefox 来找到解决方案。

在 Chrome 中,当打开任何自动完成视图并且您想要检查该元素时,当您单击任何组件时,该元素将会消失。

在 Firefox 中,它将连续显示,以便我们可以找到视图。

我做了同样的事情,我发现了一个具有 z-index 的类,

z-index: 1000

所以我只是将其更改为更像

.pac-container{
    z-index: 999999;
}

是这个 z-index 解决方案并不适合你们所有人,但我确信 Firefox 的功能一定会帮助您找到最佳解决方案。

I got the same issue, but after some struggle, I use Firefox to find solution.

In chrome when any autocomplete view is opened and you want to inspect the element, that will be disappear, when you click on any component.

but

In Firefox, that will be displayed continuously so we can find the view at all.

and I did the same thing with that, and I found a class which is having z-index

z-index: 1000

so I just changed this to more like

.pac-container{
    z-index: 999999;
}

might be this z-index solution will not work for you all, but I am sure the feature of Firefox will definitely help you to find the best solution.

给妤﹃绝世温柔 2024-09-16 01:25:28

试试这个:-
my_modal :模态 ID
使用 autocompleteappendTo 属性

$("#input_box_id").autocomplete({
来源:sourceArray/link,
追加:“#my_modal
});

参考: https://stackoverflow.com/a/22343584/5803974

Try This:-
my_modal : modal id
Use appendTo property of autocomplete

$("#input_box_id").autocomplete({<br>
source:sourceArray/link,<br>
appendTo :"#<i>my_modal</i>"<br>
});

reference: https://stackoverflow.com/a/22343584/5803974

小清晰的声音 2024-09-16 01:25:28

将此类 ui-front 插入到您的 modal-body div 中

<div class=”modal-body ui-front“>

Insert this class ui-front into your modal-body div

<div class=”modal-body ui-front“>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文