From 3c372d1da8b29df79b0366de0177a933d0494291 Mon Sep 17 00:00:00 2001 From: Julien Mougenot <jum@odoo.com> Date: Wed, 14 Aug 2019 12:35:21 +0000 Subject: [PATCH] [FIX] web: prevent unwanted click on enter keypress Pressing ENTER on a button element triggers an additionnal 'click' event. Since this 'unwanted' click caused some issues in a few cases, we prevent it. Moreover, there isn't currently any known case in which this event is useful. Before this commit: No modification of the initial behaviour on ENTER key After this commit: ENTER key pressed in abstract fields has its default behaviour suppressed --- addons/web/static/src/js/fields/abstract_field.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/addons/web/static/src/js/fields/abstract_field.js b/addons/web/static/src/js/fields/abstract_field.js index 1430c49ab18b..b6d9a63c8d6b 100644 --- a/addons/web/static/src/js/fields/abstract_field.js +++ b/addons/web/static/src/js/fields/abstract_field.js @@ -533,6 +533,12 @@ var AbstractField = Widget.extend({ } break; case $.ui.keyCode.ENTER: + // We preventDefault the ENTER key because of two coexisting behaviours: + // - In HTML5, pressing ENTER on a <button> triggers two events: a 'keydown' AND a 'click' + // - When creating and opening a dialog, the focus is automatically given to the primary button + // The end result caused some issues where a modal opened by an ENTER keypress (e.g. saving + // changes in multiple edition) confirmed the modal without any intentionnal user input. + ev.preventDefault(); ev.stopPropagation(); this.trigger_up('navigation_move', {direction: 'next_line'}); break; -- GitLab