From c22afcbe0dc8ef00a989bad3e0fcc1a71e6911a6 Mon Sep 17 00:00:00 2001 From: Joseph Caburnay Date: Wed, 2 Nov 2022 15:20:13 +0000 Subject: [PATCH] [FIX] web: custom filter display on selection field **Issue:** When creating a custom filter for a selection field, the selected value is not properly displayed. Note however that applying the filter still works. The problem is only in the displayed value. This is caused by setting the "value" attribute of the selection element which is always an empty string (because formatField doesn't properly work for selection field). However, the empty string is not the issue because it doesn't matter what "formatted value" is returned, it is not needed. The selection field's value is based on the value of the selected option. **Solution:** To properly show the display text of the selection item, we need to make sure that value of the selection field is not overridden during its onChange event. As a result, the selected option will become the value of the selection field, displaying the proper text. Therefore, in the onValueChange event handler, if the field type is selection, we don't reset the value of the the selection element. closes odoo/odoo#105420 X-original-commit: afadac5e21e6af2111ef42852243e78bb085d7c3 Signed-off-by: Aaron Bohy (aab) Signed-off-by: Joseph Caburnay (jcb) --- .../static/src/search/filter_menu/custom_filter_item.js | 5 ++++- addons/web/static/tests/search/custom_filter_item_tests.js | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/search/filter_menu/custom_filter_item.js b/addons/web/static/src/search/filter_menu/custom_filter_item.js index 48c08085521..3f8094f9146 100644 --- a/addons/web/static/src/search/filter_menu/custom_filter_item.js +++ b/addons/web/static/src/search/filter_menu/custom_filter_item.js @@ -313,7 +313,10 @@ export class CustomFilterItem extends Component { } catch (_err) { // Parsing error: nothing is done } - ev.target.value = condition.displayedValue; + // Only reset the target's value if it is not a selection field. + if (field.type !== "selection") { + ev.target.value = condition.displayedValue; + } } } diff --git a/addons/web/static/tests/search/custom_filter_item_tests.js b/addons/web/static/tests/search/custom_filter_item_tests.js index 0eb62991aa1..abf27e93fca 100644 --- a/addons/web/static/tests/search/custom_filter_item_tests.js +++ b/addons/web/static/tests/search/custom_filter_item_tests.js @@ -336,7 +336,7 @@ QUnit.module("Search", (hooks) => { }); QUnit.test("selection field: default and updated value", async function (assert) { - assert.expect(10); + assert.expect(11); const controlPanel = await makeWithSearch({ serverData, @@ -370,6 +370,11 @@ QUnit.module("Search", (hooks) => { await toggleAddCustomFilter(target); await editConditionField(target, 0, "color"); await editConditionValue(target, 0, "white"); + assert.strictEqual( + target.querySelector(".o_generator_menu_value input,.o_generator_menu_value select") + .value, + "white" + ); await applyFilter(target); assert.deepEqual(getFacetTexts(target), ['Color is "white"']);