Is it possible to have a custom handler for ESC key on the JQuery Dialog?
How to catch ESC in event in JQuery Dialog?
Asked Answered
one is already there called closeOnEscape: false –
Halfbaked
@DipeshParmar that just turns off the default escape handler, it doesn't add a custom handler. –
Politics
Yes, it's possible.
Set the closeOnEscape
option to false
and register your own keydown
handler on the .ui-dialog
element within the dialog's dialogcreate
handler.
$(element).dialog({
create: function() {
$(this).closest('.ui-dialog').on('keydown', function(ev) {
if (ev.keyCode === $.ui.keyCode.ESCAPE) {
...
}
});
...
},
closeOnEscape: false,
...
});
I use another way:
$(element).dialog({
beforeClose: function(event) {
if (event.keyCode === $.ui.keyCode.ESCAPE) {
// ...
return false;
}
}
});
$(selector-for-dialog).keyup(function(e) {
// ESC key
if ( e.keyCode === 27 ) {
// custom action
}
});
© 2022 - 2024 — McMap. All rights reserved.