Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 355
Rost Avatar asked Aug 04 '11 21:08

Rost


3 Answers

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.

like image 116
David Laberge Avatar answered Nov 15 '22 12:11

David Laberge


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.

like image 37
Lloyd Cotten Avatar answered Nov 15 '22 13:11

Lloyd Cotten


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.

like image 1
flyingfred0 Avatar answered Nov 15 '22 13:11

flyingfred0