Is it possible to have a custom handler for ESC key on the JQuery Dialog?
On computer keyboards, the Esc key Esc (named Escape key in the international standard series ISO/IEC 9995) is a key used to generate the escape character (which can be represented as ASCII code 27 in decimal, Unicode U+001B, or Ctrl + [ ).
A dialog box is a floating window with a title and content area. This window can be moved, resized, and of course, closed using "X" icon by default. jQueryUI provides dialog() method that transforms the HTML code written on the page into HTML code to display a dialog box.
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,
...
});
See http://jsfiddle.net/alnitak/EbnZr
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With