jQuery UI Dialog: OK click on Enter key
Photo by Volodymyr Hryshchenko on Unsplash
I use the jQuery dialog a lot on the inzolo budget screen. It often contains small forms. After entering the form data it is natural to hit enter and expect it to submit the form. The OK button is set to post the form data via ajax. Thanks to this stackoverflow post I found a simple way to override the enter key so that when the dialog box is open, it simulates pressing the OK button. I simply added this jQuery snippet to control all my dialogs that have a form & OK button.
$('#dialog').live('keyup', function (e) {
if (e.keyCode == 13) {
$(':button:contains("OK")').click()
}
})