I would like to be able to close a ModalWindow when the user presses a key, in my case ESC.
I have a Javascript listener for the keypress which calls the click event of the cancel button's ID:
jQuery("#"+modalWindowInfo.closeButtonId).click();
Is this the correct way to do it?
I am wondering because it works in Chrome but not in FF, but it could be due my specific implementation.
The example above is good, very good, however there is one issue which may be crucial for some programming users (was for me).
For the actual close to happen there are 2 ajax requests happening - first one is issued with the
CloseOnESCBehavior
which callswindow.close
. MW.close() would render javascript which would first do call to server to ask itswindowClosedCallback
, and would only then close (hide contents of) the modal window.I'd suggest instead doing something like this - in the code of ModalWindow ctor:
The 'right' way to do it is to call the server, then close it with the response. You can do this with an ajax behavior:
ModalTestPage.java
ModalTestPage.html
Also, you can use Wicket Jquery UI
HTML
Java
And the ESC key works fine. You should see this aproach at Wicket JQuery UI demo page