1

I want submit form for Jquery dialog by pressing enter key.

HTML

<!-- Pin Notification Form -->
<div id="pin-dialog-form" title="Verification Pin">
   <div id="agent_pin_container">
      <input type="password" name="verification_pin" id="verification_pin"
      value="" class="form-control" placeholder="Verification Pin" />
</div>
</div>

JQUERY

$( "#pin-dialog-form" ).dialog({
autoOpen: false,
height: 200,
width: 300,
modal: true,
buttons: {
    "Submit": function() {
        // PROCESS
    },
    Cancel: function() {
        $( this ).dialog( "close" );
    }
},
close: function() {
    $( this ).dialog( "close" );
}
});

Now, I can not use this type of code in here, if (e.keyCode == 13) {. Because, the form is submitted by modal window itself. on the other hand I can not use this,

open: function() {
  $(this).parents('.ui-dialog-buttonpane button:eq(0)').focus(); 
}

because, I need to enter PIN first then focus on submit button. Is there any other way to do it? Thanks.

4
  • possible duplicate of Submitting a form on 'Enter' with jQuery? Commented Aug 22, 2014 at 14:31
  • I already mention those scenario in my question. It's not duplicate of that question. Commented Aug 22, 2014 at 14:34
  • You should combine it with stackoverflow.com/questions/2878983/… then Commented Aug 22, 2014 at 14:35
  • @LucaB.: Can you please combine those 2 in here. I don't know how to do that. If you can then that would be a great help. thanks. Commented Aug 22, 2014 at 14:38

1 Answer 1

2

As per comments you should be able to grab keypress document-wide using:

$(document).keypress(function(e){
  if (e.keyCode == 13) {
    // CODE TO SUBMIT THE FORM either AJAX or *form*.submit()
    // CODE TO CLOSE THE MODAL
  }
});

sources:

Submitting a form on 'Enter' with jQuery?

Capture key press without placing an input element on the page?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.