I ran into an interesting issue with jQueryUI autocomplete in a dialog box.
My dialog HTML looks like this:
<div id="copy_dialog">
<table>
<tbody>
<tr>
<th>Title:</th>
<td><input type="text" class="title" name="title"></td>
</tr>
<tr>
<th>Number:</th>
<td><input type="text" name="number"></td>
</tr>
</tbody>
</table>
</div>
When I run the jQueryUI autocomplete on the above HTML, it works perfect.
When I open it up using dialog
$('#copy').click(function()
{
$('#copy_dialog').dialog({
autoOpen: true,
width: 500,
modal: false,
zIndex: 10000000,
title: 'Duplicate',
buttons: {
'Cancel': function()
{
$(this).dialog('close');
},
'Save': function()
{
$(this).dialog('close');
}
}
});
return false;
});
Then in FireBug, I can see autocomplete is still working. It's requesting and receiving results, but I no longer see a list of options below the input field.
My thought is that this has something to do with the zIndex on the dialog box being much greater than what the autocomplete menu gives, but I don't know for sure. I'm still researching exact details of what's happening, but I'm hoping someone here will have some idea for me.
Edit I tried removing the zIndex from the dialog and my autocomplete starts showing up. Unfortunately, I need that zIndex value to get over the dreadfully high zIndex of the menubar, which I can't change (don't have access to that area of the code). So if there's a way to add a zIndex to the autocomplete, that would be fantastic; until then, I'll probably just remove the zIndex from the dialog and make sure it doesn't show up around the menubar area.
This link worked for me.
https://github.com/taitems/Aristo-jQuery-UI-Theme/issues/39
Am using jquery-ui-1.10.3.
I configured the autocomplete combobox inside the "open" event of the jquery dialog.
Through pursuing this problem myself I discovered that
appendTo
has to be set before the dialog is opened. The same seems to apply to setting (or modifying) the source property.This might just be a byproduct of what dialog open does, or not correctly addressing the element. But the order things happen seems to matter.
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/
Try setting the
appendTo
option to"#copy_dialog"
:This option specifies which element the autocomplete menu is appended to. By appending the menu to the dialog, the menu should inherit the correct z-index.
Super simple solution. Increase the z-index for the autocomplete. When it is active I am pretty sure you want it on top :)
user1357172's solution worked for me but in my opinion it needs two imprevements.
If
appendTo
is set tonull
, we can find the closest.ui-front
element instead of.ui-dialog
, because ourautocomplete
should be already attached to it. Then we should change thez-index
only for related widget (related ul list) instead of changing all existing elements with class.ui-autocomplete.ui-front
. We can find related widget by usingelem.autocomplete('widget')
Solution:
BTW this solution works but it looks bit hacky, so it is not probably the best one.