jQuery UI modal dialog captures all keypress so I can't input text inside it
Asked Answered
P

4

20

I create modal dialog with form inside it (with some text input). And I just can't enter the text inside the textbox. Dialog blocks keyboard input.

Here is my simplified example:

<div id="modal-dialog">
    <label for="my-text">TRY to input text...</label>
    <textarea id="my-text" style="position:relative; z-index:1"></textarea>
</div>
<script type="text/javascript">
    var dialog = $('#modal-dialog').dialog({ modal: true });
</script>

Note: You may ask - why did I mentioned about "position:relative; z-index:1"? Because it works fine without it. But I can't remove it because of design.

Note: not modal dialog works fine too.

I'm using jQuery 1.6.2 + jQuery UI 1.8.14

Peevish answered 4/8, 2011 at 21:56 Comment(1)
Have you try to remove the style in the textarea? Just for the fun of it. The modal functionality is a z-index div above the rest of the document. It might just be that?Deficit
D
19

The z-index is the problem. Here is an exemple ( http://jsfiddle.net/c3BPP/ ) of your code with a bigger z-index and it works.

Deficit answered 4/8, 2011 at 23:28 Comment(1)
Thanks, it helps. But it seems like jQuery UI bug to me.Peevish
L
5

You can also lower the z-index of the JQuery dialog:

var dialog = $('#modal-dialog').dialog({ 
    modal: true,
    zIndex: 500
});

By default, it is 1000. Of course your relative or absolute positioned elements needing text input need to be greater than the z-index of the dialog still.

Loophole answered 10/9, 2011 at 15:31 Comment(0)
K
1

I found that the <form> tag in my dialog was getting a z-index of 1, preventing any of the controls from working. Instead of changing the z-index for each control, simply changing the z-index of the <form> tag to 1010 (a value higher than the default of the dialog) worked for me.

Kellen answered 17/3, 2012 at 3:0 Comment(0)
A
0

Adding tabindex="-1" helped me resolve this problem.

Here's an example:

 <div class="modal fade" tabindex="-1" id="error" role="dialog">
Archaeopteryx answered 3/5, 2016 at 17:50 Comment(1)
You seem to have posted before finishing what you were writing. Where should OP put this attribute? What does it do?Streetcar

© 2022 - 2024 — McMap. All rights reserved.