title: jQuery dialog Enter to submit (without form focus)
body: <h2>Background</h2>
  
  <p>Using a jQuery modal dialog to present a form. The form has an autocomplete field. When the user selects an option from the autocomplete drop-down, the form loses focus. The jQuery dialog detects the ESC key, however ENTER key is never detected. Consider one of several forms (on the same page), having a variety of buttons:</p>
  
  <p><img src="https://i.imgur.com/FRrmM.png" /></p>
  
  <h2>Code</h2>
  
  <p>The source code to detect when the ENTER key is pressed:</p>
  
  <pre><code>  $(form).keyup(function( e ) {
      // Submit and close when Enter key pressed by triggering the accept button.
      //
      if( e.keyCode == $.ui.keyCode.ENTER ) {
        sequenceNumber = 0;
        $(this).parent().find( "#accept" ).trigger( 'click' );
      }
    });
  </code></pre>
  
  <p>This works as expected (the "accept" button is triggered and the server receives the values just fine) whenever any field of the form has focus.</p>
  
  <h2>Problem</h2>
  
  <p>When the dialog is shown but no fields have focus (e.g., the user clicks on "fish fillet" in the above image), then presses ENTER, the keyup event is never fired.</p>
  
  <h2>Question</h2>
  
  <p>How can you receive an ENTER event when the form does not have focus, but the jQuery dialog is still open? (In the same way that the jQuery dialog receives the ESC keypress to cancel and close the dialog.)</p>
  
  <p>Thank you!</p>