EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: jkdoyle on May 22, 2017, 12:53:48 PM



Title: Close Window, Dialog, Modal on Keypress
Post by: jkdoyle on May 22, 2017, 12:53:48 PM
I can't quite figure this one out.

When I open a dialog/window, is there a way to have it close on any keypress? And then once it has closed to stop the keydown/keypress function (so that I can refocus on form elements)?

For example, how would I close $("mydialog").dialog();

Thanks
jimmy



Title: Re: Close Window, Dialog, Modal on Keypress
Post by: jarry on May 23, 2017, 07:30:37 AM
Listen to the keypress on the dialog, call 'close' method to close the dialog. Please look at this code:
Code:
var dlg = $('#dlg');
dlg.window('window').attr('tabindex',1).focus().bind('keyup', function(e){
if (e.keyCode == 27){ // ESC
dlg.window('close');
}
})