模态 ui 对话框内的 jquery UI 自动完成 - 建议未显示?
我正在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(19)
我在搜索同一问题时遇到了这个答案,但是没有一个解决方案正是我想要的。
使用
appendTo
工作了,有点...自动完成项目显示在它们应该出现的地方,但是它完全把我的对话框窗口变成了一堆未正确重新定位的 div 元素的乱码。因此,在我自己的 css 文件中,我创建了以下内容:
我确信 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:
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.
使用 jQuery UI 1.10 时,不应乱用 z 索引 (http: //jqueryui.com/upgrade-guide/1.10/#removed-stack-option)。
appendTo
选项有效,但会将显示限制为对话框的高度。要修复此问题:请确保自动完成元素处于正确的 DOM 顺序:autocomplete.insertAfter(dialog.parent())
示例
<强>单击对话框后更新 z-index 问题
单击对话框后自动完成的 z-index 似乎发生了变化(如 MatteoC 报告)。下面的解决方法似乎可以解决此问题:
请参阅小提琴: https://jsfiddle.net/sv9L7cnr/
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
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/
我在引导箱中解决了这个问题,如下所示:
您只需将结果列表附加到您的表单中。
I solved it in bootbox like this:
You only have to append the result list to your form.
在您的
autocomplete
实现中,添加appendTo: "#search_modal"
,其中 search_modal 是模态框的 ID。In your
autocomplete
implementation, addappendTo: "#search_modal"
, where search_modal is ID of your modal.对于同一对话框中的一个或多个自动完成:
for one or multiples autocompletes in the same dialogbox:
注意:$('#divName') divName 将是模态体的名称。
例子:
Note: $('#divName') divName will be the name of modal body.
EXAMPLE:
我遇到了同样的问题,当我想到:
始终在设置自动完成之前声明您的对话框。
我已经切换了它们,等等!
自动完成功能围绕您的目标输入进行配置。 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.
我解决了将属性
z-index:1500
添加到我的 div 中的问题jquery.autocomplete.css 因为 Jquery UI 对话框将 z-index 放在
1000 和 1005
I solved adding atribute
z-index:1500
to my divs injquery.autocomplete.css because Jquery UI Dialog put z-index between
1000 and 1005
我们有同样的问题。我们刚刚更新了 CSS,以便 z-index 足够高并且不能被覆盖:
由于附加到 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:
As append to body makes the dropdown child of $window you need to make all dropdown-menu to the new z-index.
我最近也遇到了同样的问题。将其添加到我的 css 文件中为我解决了这个问题:
我首先尝试了初始 z-index 值
1006
,但这不起作用。增加价值对我有用。I recently had the same issue. Adding this to my css-file solved it for me:
I first tried your initial z-index value of
1006
, but that didn't work. Increasing the value worked for me.我也有这个问题。我正在 UserFrosting 工作,它有 bootstrap 和 select2,但核心没有 jquery-ui 。我的自动完成功能位于模态弹出窗口内,其中脚本标记和 $(document).ready 位于模态表单的 html 之后。在追踪各种不存在的冲突并尝试将 select2 (v 4) 放入组合框之后,我回到了 css hack 并且这有效:
我的环境是
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:My environment is
我遇到了同样的问题,已通过添加以下样式解决:
I was facing same issue , It has been resolved by adding bellow styles :
在我的例子中,在 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.将以下方法添加到您的 javascript 中,并从 body 元素的 onload 事件中调用它:
它对我有用:) 我通过查看模式对话框的计算样式来了解它的 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:
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)
这对我来说很有效:
This did the trick for me:
Johann-S 的回答这里对我有用。
只需将 data-focus="false" 添加到调用模态的按钮或链接,这样
您就不必弄乱 z 索引或覆盖 bootstrap 的强制焦点(它不会被调用)
Johann-S ' answer here worked for me.
simply add data-focus="false" to the button or link calling the modal like
This way you don't have to mess with z-indexes or override bootstrap's enforce focus (it's not called)
我遇到了同样的问题,但经过一番努力后,我使用 Firefox 来找到解决方案。
但
我做了同样的事情,我发现了一个具有 z-index 的类,
所以我只是将其更改为更像
是这个 z-index 解决方案并不适合你们所有人,但我确信 Firefox 的功能一定会帮助您找到最佳解决方案。
I got the same issue, but after some struggle, I use Firefox to find solution.
but
and I did the same thing with that, and I found a class which is having z-index
so I just changed this to more like
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.
试试这个:-
my_modal :模态 ID
使用
autocomplete
的appendTo
属性$("#input_box_id").autocomplete({
来源:sourceArray/link,
追加:“#my_modal”
});
参考: https://stackoverflow.com/a/22343584/5803974
Try This:-
my_modal : modal id
Use
appendTo
property ofautocomplete
$("#input_box_id").autocomplete({<br>
source:sourceArray/link,<br>
appendTo :"#<i>my_modal</i>"<br>
});
reference: https://stackoverflow.com/a/22343584/5803974
将此类 ui-front 插入到您的 modal-body div 中
Insert this class ui-front into your modal-body div