From fe9b2a8a7125640a39738292f397495f0d39b5eb Mon Sep 17 00:00:00 2001 From: Mathieu Duckerts-Antoine Date: Thu, 2 Nov 2023 13:17:13 +0100 Subject: [PATCH] [FIX] web: model field selector: communicate path in debug input MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Have the model field selector popover open, modify the path in the debug input (bottom input available when isDebugMode=true), then close the popover by clicking away. The model field selector is correctly updated but its parent does not receive the right path. This happens because onClose is called before the function update passed to the popover is called. Here we make the popover communicate its current path on each input event so that if the popover has to be closed, the model field selector knows which path to communicate to its parent. closes odoo/odoo#141362 X-original-commit: 6a4e4221a1daa474217070f6a78602a962bbcf65 Related: odoo/enterprise#50337 Signed-off-by: Rémi Rahir (rar) --- .../model_field_selector.js | 6 ++- .../model_field_selector_popover.xml | 2 +- .../tests/core/model_field_selector_tests.js | 38 +++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/core/model_field_selector/model_field_selector.js b/addons/web/static/src/core/model_field_selector/model_field_selector.js index bf666287058..08154c48cf5 100644 --- a/addons/web/static/src/core/model_field_selector/model_field_selector.js +++ b/addons/web/static/src/core/model_field_selector/model_field_selector.js @@ -57,9 +57,11 @@ export class ModelFieldSelector extends Component { this.popover.open(currentTarget, { resModel: this.props.resModel, path: this.props.path, - update: (path) => { + update: (path, debug = false) => { this.newPath = path; - this.updateState({ ...this.props, path }, true); + if (!debug) { + this.updateState({ ...this.props, path }, true); + } }, showSearchInput: this.props.showSearchInput, isDebugMode: this.props.isDebugMode, diff --git a/addons/web/static/src/core/model_field_selector/model_field_selector_popover.xml b/addons/web/static/src/core/model_field_selector/model_field_selector_popover.xml index 447d7e58692..2e4a9c79017 100644 --- a/addons/web/static/src/core/model_field_selector/model_field_selector_popover.xml +++ b/addons/web/static/src/core/model_field_selector/model_field_selector_popover.xml @@ -52,7 +52,7 @@ diff --git a/addons/web/static/tests/core/model_field_selector_tests.js b/addons/web/static/tests/core/model_field_selector_tests.js index 1c6a4e5c105..84179ccf0b0 100644 --- a/addons/web/static/tests/core/model_field_selector_tests.js +++ b/addons/web/static/tests/core/model_field_selector_tests.js @@ -963,4 +963,42 @@ QUnit.module("Components", (hooks) => { assert.containsNone(target, ".o_model_field_selector .fa.fa-times"); assert.verifySteps([`path is ""`]); }); + + QUnit.test("Modify path in popover debug input and click away", async (assert) => { + class Parent extends Component { + setup() { + this.path = "foo"; + } + onUpdate(path) { + this.path = path; + assert.step(path); + this.render(); + } + } + Parent.components = { ModelFieldSelector }; + Parent.template = xml` + + `; + + await mountComponent(Parent); + assert.deepEqual(getModelFieldSelectorValues(target), ["Foo"]); + + await openModelFieldSelectorPopover(target); + const input = target.querySelector( + ".o_model_field_selector_popover .o_model_field_selector_debug" + ); + input.value = "foooooo"; + await triggerEvent(input, null, "input"); + assert.deepEqual(getModelFieldSelectorValues(target), ["Foo"]); + + await click(target); + assert.deepEqual(getModelFieldSelectorValues(target), ["foooooo"]); + assert.verifySteps(["foooooo"]); + }); });