Following answers like this one, I wanted to hook the enter key press on a JQuery dialog so I can trigger the same event as when you click "OK", however the event is never called, and consequently I'm never getting the alert "it worked":
$("#logout_popup").dialog(
{
title: "Log Out",
width: 'auto',
height: 'auto',
modal: true,
draggable: false,
resizable: false,
open: function(e) {
$('.ui-widget-overlay').hide().fadeIn(600);
//This is the event that's never called
$(e.target).keydown(function(ev) {
alert("Worked!");
});
},
show: {
effect: 'fade',
duration: 600
},
hide: {
effect: 'fade',
duration: 600
},
buttons: [
{
text: "Yes",
click: logout
},
{
text: "No",
click: function() {
$('#logout_popup').dialog('close');
}
}
],
close: clear_forms
});
Most of the dialog settings are irrelevant, but I included them all just in case. How come the event is never being called?
I should add that if I use the event $("#logout_popup").keydown, it also doesn't work, but if I use $(document).keydown, it does work (although I'd rather not have to filter every single event in the document.