From a4b3513743d107a7028db3c67a925f5a854728c9 Mon Sep 17 00:00:00 2001 From: Ziggy Trotter Date: Mon, 25 Sep 2023 14:43:19 +0200 Subject: [PATCH 1/6] Bugfix: Clicking 'Enter' inside of triggers wrong event. --- var/httpd/htdocs/js/Core.Form.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/var/httpd/htdocs/js/Core.Form.js b/var/httpd/htdocs/js/Core.Form.js index c8cc91165c3..1f3fcfc5072 100644 --- a/var/httpd/htdocs/js/Core.Form.js +++ b/var/httpd/htdocs/js/Core.Form.js @@ -292,6 +292,16 @@ Core.Form = (function (TargetNS) { // Once there was any modification, do not check it any more. $("form input, select, textarea").off('change', FormModified); } + + /** + * This makes all forms submittable by using Enter inside inputs. + */ + $('body').on('keydown', 'input', function (Event) { + if (Event.keyCode == 13) { + $('form').find(':submit').last().click(); + } + Event.preventDefault() + }); /** * This makes all forms submittable by using Ctrl+Enter inside textareas. @@ -302,7 +312,7 @@ Core.Form = (function (TargetNS) { if ((Event.ctrlKey || Event.metaKey) && Event.keyCode == 13) { // We need to click() instead of submit(), since click() has // a few useful event handlers tied to it, like validation. - $(this.form).find(':submit').first().click(); + $(this.form).find(':submit').last().click(); } }); From fa1d81b1f1283bf88eb87b6da734e5e259aaad27 Mon Sep 17 00:00:00 2001 From: Ziggy Trotter Date: Mon, 25 Sep 2023 16:30:41 +0200 Subject: [PATCH 2/6] Added preventDefault() to avoid multiple events triggering --- var/httpd/htdocs/js/Core.Form.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/var/httpd/htdocs/js/Core.Form.js b/var/httpd/htdocs/js/Core.Form.js index 1f3fcfc5072..f87d4335f71 100644 --- a/var/httpd/htdocs/js/Core.Form.js +++ b/var/httpd/htdocs/js/Core.Form.js @@ -292,7 +292,7 @@ Core.Form = (function (TargetNS) { // Once there was any modification, do not check it any more. $("form input, select, textarea").off('change', FormModified); } - + /** * This makes all forms submittable by using Enter inside inputs. */ @@ -314,6 +314,7 @@ Core.Form = (function (TargetNS) { // a few useful event handlers tied to it, like validation. $(this.form).find(':submit').last().click(); } + Event.preventDefault() }); Core.Init.RegisterNamespace(TargetNS, 'APP_MODULE'); From 06efcf891bd2c3d4be0ef98c5a47a99e6aba2c3a Mon Sep 17 00:00:00 2001 From: Zigfield Trotter Date: Fri, 19 Jan 2024 08:47:35 +0100 Subject: [PATCH 3/6] Corrected issue preventing expected behaviour --- var/httpd/htdocs/js/Core.Form.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/var/httpd/htdocs/js/Core.Form.js b/var/httpd/htdocs/js/Core.Form.js index f87d4335f71..1a40c1b8f93 100644 --- a/var/httpd/htdocs/js/Core.Form.js +++ b/var/httpd/htdocs/js/Core.Form.js @@ -298,9 +298,9 @@ Core.Form = (function (TargetNS) { */ $('body').on('keydown', 'input', function (Event) { if (Event.keyCode == 13) { + Event.preventDefault() $('form').find(':submit').last().click(); } - Event.preventDefault() }); /** @@ -312,9 +312,9 @@ Core.Form = (function (TargetNS) { if ((Event.ctrlKey || Event.metaKey) && Event.keyCode == 13) { // We need to click() instead of submit(), since click() has // a few useful event handlers tied to it, like validation. + Event.preventDefault() $(this.form).find(':submit').last().click(); } - Event.preventDefault() }); Core.Init.RegisterNamespace(TargetNS, 'APP_MODULE'); From 29ac118108b1ecf419d0a13a680c03baf240ba04 Mon Sep 17 00:00:00 2001 From: Ziggy Trotter <142500923+ZTrotter@users.noreply.github.com> Date: Fri, 19 Jan 2024 11:37:04 +0100 Subject: [PATCH 4/6] Update var/httpd/htdocs/js/Core.Form.js Added semicolon Co-authored-by: Niklas --- var/httpd/htdocs/js/Core.Form.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/var/httpd/htdocs/js/Core.Form.js b/var/httpd/htdocs/js/Core.Form.js index 1a40c1b8f93..25ae194bfe4 100644 --- a/var/httpd/htdocs/js/Core.Form.js +++ b/var/httpd/htdocs/js/Core.Form.js @@ -298,7 +298,7 @@ Core.Form = (function (TargetNS) { */ $('body').on('keydown', 'input', function (Event) { if (Event.keyCode == 13) { - Event.preventDefault() + Event.preventDefault(); $('form').find(':submit').last().click(); } }); From f80cf2c5d9ec8d7b5076a41796d8f1e1db885dbb Mon Sep 17 00:00:00 2001 From: Ziggy Trotter <142500923+ZTrotter@users.noreply.github.com> Date: Fri, 19 Jan 2024 11:37:19 +0100 Subject: [PATCH 5/6] Update var/httpd/htdocs/js/Core.Form.js Added semicolon Co-authored-by: Niklas --- var/httpd/htdocs/js/Core.Form.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/var/httpd/htdocs/js/Core.Form.js b/var/httpd/htdocs/js/Core.Form.js index 25ae194bfe4..f8b15a90644 100644 --- a/var/httpd/htdocs/js/Core.Form.js +++ b/var/httpd/htdocs/js/Core.Form.js @@ -312,7 +312,7 @@ Core.Form = (function (TargetNS) { if ((Event.ctrlKey || Event.metaKey) && Event.keyCode == 13) { // We need to click() instead of submit(), since click() has // a few useful event handlers tied to it, like validation. - Event.preventDefault() + Event.preventDefault(); $(this.form).find(':submit').last().click(); } }); From d48981ff004e8fc7478d125a595ee031d72cb433 Mon Sep 17 00:00:00 2001 From: Zigfield Trotter Date: Mon, 8 Apr 2024 13:17:24 +0200 Subject: [PATCH 6/6] Bugfix: Forms without clickable a button now submittable via Enter key. --- var/httpd/htdocs/js/Core.Form.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/var/httpd/htdocs/js/Core.Form.js b/var/httpd/htdocs/js/Core.Form.js index f8b15a90644..5d721164c20 100644 --- a/var/httpd/htdocs/js/Core.Form.js +++ b/var/httpd/htdocs/js/Core.Form.js @@ -297,9 +297,9 @@ Core.Form = (function (TargetNS) { * This makes all forms submittable by using Enter inside inputs. */ $('body').on('keydown', 'input', function (Event) { - if (Event.keyCode == 13) { + if (Event.keyCode == 13 && $(this).closest('form').find(':submit').length > 0) { Event.preventDefault(); - $('form').find(':submit').last().click(); + $(this.form).find(':submit').last().click(); } });