Skip to content

Commit

Permalink
fix(form): avoid double submit on enterkey
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
lubber-de committed Aug 9, 2021
1 parent 3fc5491 commit d5d7bab
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/definitions/behaviors/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit d5d7bab

Please sign in to comment.