EasyUI Forum
April 19, 2024, 01:09:31 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Close Window, Dialog, Modal on Keypress  (Read 4977 times)
jkdoyle
Newbie
*
Posts: 25


View Profile Email
« 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

Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 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');
}
})
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!