From 7f672bd04fdd28a35d35ccabadb61325ac8f294d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 4 Jul 2016 18:09:27 +0200 Subject: [PATCH] Bug #3385: Close confirmation dialogs with the enter key (cherry picked from commit 4f528679440a6eecae223151db1e2169693ffeb8) --- src/sunstone/public/app/utils/dialogs/confirm.js | 9 +++++++++ .../public/app/utils/dialogs/generic-confirm.js | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/sunstone/public/app/utils/dialogs/confirm.js b/src/sunstone/public/app/utils/dialogs/confirm.js index 4eb2aadd38..957fac7c6c 100644 --- a/src/sunstone/public/app/utils/dialogs/confirm.js +++ b/src/sunstone/public/app/utils/dialogs/confirm.js @@ -58,6 +58,15 @@ define(function(require) { } function _setup(dialog) { + $(dialog).keypress(function (e) { + if (e.which == 13 || e.keyCode == 13) { + $('#confirm_proceed', dialog).click(); + return false; + } else { + return true; + } + }); + // Submit action is configured in sunstone.js since it's an action_button return false; } diff --git a/src/sunstone/public/app/utils/dialogs/generic-confirm.js b/src/sunstone/public/app/utils/dialogs/generic-confirm.js index 1efea60629..f0423d370b 100644 --- a/src/sunstone/public/app/utils/dialogs/generic-confirm.js +++ b/src/sunstone/public/app/utils/dialogs/generic-confirm.js @@ -88,8 +88,18 @@ define(function(require) { function _setup(context) { var that = this; + $(context).keypress(function (e) { + if (e.which == 13 || e.keyCode == 13) { + $('#' + DIALOG_ID + 'Form', context).submit(); + return false; + } else { + return true; + } + }); + $('#' + DIALOG_ID + 'Form', context).submit(function(e) { - if (that.params.buttons != undefined){ + // With more than one button, skip + if (that.params.buttons != undefined && that.params.buttons.length > 1){ e.preventDefault(); return false; } @@ -97,7 +107,7 @@ define(function(require) { Sunstone.getDialog(DIALOG_ID).hide(); if (that.params.submit != undefined){ - that.params.submit(this); + that.params.submit[0](this); } return false;