From c200b0cc8a9f1b4d21dd0b3638d4635be3f6bd18 Mon Sep 17 00:00:00 2001 From: FrancoisGe Date: Wed, 24 Aug 2022 09:25:49 +0000 Subject: [PATCH] [FIX] web: many2one close "No records" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, when a many2one's input shows the choice "No records", the dropdown does not close. Cause: When blurring, the many2one will select its first item. In our case, "No records" is not selectable and it will not close the dropdown. How to reproduce: - go to a form view with a many2one field - insert a non-existent value in the many2one ("No records" is displayed) - leave the many2one input ("blur" event) Result before: The dropdown containing "No records" is still open. Result after: The dropdown containing "No records" is closed. closes odoo/odoo#98799 Signed-off-by: Michaƫl Mattiello --- addons/web/static/src/core/autocomplete/autocomplete.js | 1 + .../web/static/tests/views/fields/many2one_field_tests.js | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/addons/web/static/src/core/autocomplete/autocomplete.js b/addons/web/static/src/core/autocomplete/autocomplete.js index 87a14958cfe..7b29cf4779a 100644 --- a/addons/web/static/src/core/autocomplete/autocomplete.js +++ b/addons/web/static/src/core/autocomplete/autocomplete.js @@ -120,6 +120,7 @@ export class AutoComplete extends Component { const option = this.sources[indices[0]].options[indices[1]]; if (option.unselectable) { this.inputRef.el.value = ""; + this.close(); return; } diff --git a/addons/web/static/tests/views/fields/many2one_field_tests.js b/addons/web/static/tests/views/fields/many2one_field_tests.js index 58a0e44b2d6..ffec46eadd2 100644 --- a/addons/web/static/tests/views/fields/many2one_field_tests.js +++ b/addons/web/static/tests/views/fields/many2one_field_tests.js @@ -3073,6 +3073,13 @@ QUnit.module("Fields", (hooks) => { ".o_field_many2one[name=product_id] .o_m2o_no_result", "there should be option for 'No records'" ); + + await triggerEvent(target, ".o_field_many2one[name=product_id] input", "blur"); + assert.containsNone( + target, + ".o_field_many2one[name=product_id] .o_m2o_no_result", + "there should be option for 'No records'" + ); } );