key down isn't called when there is no input field
i can't catch the escape event in there there is no input field in the dialog.
in the sample bellow it's working only if there is input, when i remove it, it stop working.
how can i catch the event of pressing esc or enter in this case?
<div id="dialog-confirm2">
Dialog
<input type="text" /> <%--this is the redundent input i don't need in the dialog--%>
</div>
(function () {
var dialog = $("#dialog-confirm2")
.dialog({
resizable: false,
height: 150,
modal: true,
closeOnEscape: false, //hide x button
})
.on('keydown', function (evt) {
if (evt.keyCode === $.ui.keyCode.ESCAPE) {
alert('test');
<%--more actions to do here--%>
dialog.dialog('close');
}
evt.stopPropagation();
});
}());