From c3f93b1918c889146d941cbd29c933b7c5e6da5c Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Tue, 11 May 2021 16:00:43 +0200 Subject: [PATCH] misc: fix email autocorrect behavior when pressing enter (#50763) --- .../authentic2/js/email_domains_suggestions.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/authentic2/static/authentic2/js/email_domains_suggestions.js b/src/authentic2/static/authentic2/js/email_domains_suggestions.js index 1f0b0017..1eeb6f57 100644 --- a/src/authentic2/static/authentic2/js/email_domains_suggestions.js +++ b/src/authentic2/static/authentic2/js/email_domains_suggestions.js @@ -66,9 +66,12 @@ String.prototype.similarity = function(string) { return weight; } +var change_triggered = false; + $(function() { var $domain_hint_div; $('input[type=email]').on('change', function() { + change_triggered = true; var $email_input = $(this); var suggested_domains = $(this).data('suggested-domains').split(':'); var val = $email_input.val(); @@ -87,7 +90,16 @@ $(function() { } if (highest_ratio > 0.80 && highest_ratio < 1) { $domain_hint_div = $('div.field-live-hint') - $domain_hint_div.find('button.action').on('click', function() { + $domain_hint_div.find('button.action').off().on('click', function(event) { + if(change_triggered && $domain_hint_div.is(':visible') && !event.screenX && !event.screenY) { + // prevent applying the correction just after showing hint if enter key is used + change_triggered = false; + return false; + } + if(!$domain_hint_div.is(':visible')) { + // allow submitting form with enter key if there is no hint + return true; + } $email_input.val($email_input.val().replace(/@.*/, '@' + $(this).data('suggestion'))); $email_input.trigger('change'); $domain_hint_div.hide(); -- 2.20.1