Q:

Keypress is not called anymore after form inside jquery ui modal box is hidden

I have a jquery UI modal box that contains a form.
I declared keypress event to handle Enter being pressed.
If I hide the form contained in the modal box, the keypress event is not called anymore.
This behaviour is reproduced here: https://jsfiddle.net/patrick29/jqp4wp77/
$('.dialog').on('keypress', function(e) {
    if (e.keyCode == $.ui.keyCode.ENTER) {
        submit();
    }
});
function submit() {
    alert('ok');
    $('.dialog form').hide();
}

First time Enter is pressed I receive ok message. Then form is hidden and second time Enter is pressed I do not receive ok message anymore.
Do you know why and how I can hide form and still have keypress event work ?
Thanks!

A:

You can do something like this instead of .hide();
$('.dialog form').css({
  opacity: 0
});

https://jsfiddle.net/nr5fptd2/1/

