From 4b7b89b04072f8bb44da45bb321c62002b6a11ed Mon Sep 17 00:00:00 2001 From: FrancoisGe Date: Thu, 28 Jul 2022 09:44:05 +0000 Subject: [PATCH] [FIX] web: duplicate blank option in selection field Before this commit, in a field selection, it was possible to have two blank options. To reproduce this problem, you need to have a non required selection field and one of the selection sent by the server has the value false. Our solution is to ignore the false selection returned by the server and add the false option only if the field is not required. closes odoo/odoo#96951 Signed-off-by: Aaron Bohy (aab) --- .../font_selection/font_selection_field.js | 8 ++- .../font_selection/font_selection_field.xml | 7 --- .../views/fields/selection/selection_field.js | 15 ++++-- .../fields/selection/selection_field.xml | 7 --- .../fields/font_selection_field_tests.js | 17 +++++++ .../views/fields/selection_field_tests.js | 51 +++++++++++++++++++ 6 files changed, 86 insertions(+), 19 deletions(-) diff --git a/addons/web/static/src/views/fields/font_selection/font_selection_field.js b/addons/web/static/src/views/fields/font_selection/font_selection_field.js index fb10e1a7401..6b2024f8677 100644 --- a/addons/web/static/src/views/fields/font_selection/font_selection_field.js +++ b/addons/web/static/src/views/fields/font_selection/font_selection_field.js @@ -9,7 +9,13 @@ const { Component } = owl; export class FontSelectionField extends Component { get options() { - return Array.from(this.props.record.fields[this.props.name].selection); + const options = this.props.record.fields[this.props.name].selection.filter( + (option) => option[0] !== false && option[1] !== "" + ); + if (!this.isRequired) { + options.unshift([false, this.props.placeholder || ""]); + } + return options; } get isRequired() { return this.props.record.isRequired(this.props.name); diff --git a/addons/web/static/src/views/fields/font_selection/font_selection_field.xml b/addons/web/static/src/views/fields/font_selection/font_selection_field.xml index 93ae586dbc1..b079da1164a 100644 --- a/addons/web/static/src/views/fields/font_selection/font_selection_field.xml +++ b/addons/web/static/src/views/fields/font_selection/font_selection_field.xml @@ -7,13 +7,6 @@ - -