From d5d7bab218daac4f9c89f83337e41abf17392b4a Mon Sep 17 00:00:00 2001 From: Marco 'Lubber' Wienkoop Date: Mon, 9 Aug 2021 09:03:57 +0200 Subject: [PATCH] fix(form): avoid double submit on enterkey Whenever the enter key is pressed inside a form field, it triggers a form submit. However, this is also a browser default behavior, thus the event was called twice. Especially for IE11 this was causing the normal submit to not function anymore. I also made sure that native input fields of type "reset", "button" or "submit" are not fetched for input validation anymore (just in case someone would try). A native "reset" button would otherwise also submit the form (when enter is pressed on focussed button) --- src/definitions/behaviors/form.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/definitions/behaviors/form.js b/src/definitions/behaviors/form.js index 747f0956bc..996c3367f9 100644 --- a/src/definitions/behaviors/form.js +++ b/src/definitions/behaviors/form.js @@ -419,6 +419,7 @@ $.fn.form = function(parameters) { $field.one('keyup' + eventNamespace, module.event.field.keyup); module.submit(); module.debug('Enter pressed on input submitting form'); + event.preventDefault(); } keyHeldDown = true; } @@ -1596,7 +1597,7 @@ $.fn.form.settings = { selector : { checkbox : 'input[type="checkbox"], input[type="radio"]', clear : '.clear', - field : 'input:not(.search):not([type="file"]), textarea, select', + field : 'input:not(.search):not([type="file"]):not([type="reset"]):not([type="button"]):not([type="submit"]), textarea, select', group : '.field', input : 'input:not([type="file"])', message : '.error.message',