diff --git a/addons/web/static/src/core/domain_selector_dialog/domain_selector_dialog.js b/addons/web/static/src/core/domain_selector_dialog/domain_selector_dialog.js index 207aa307b0d..2be8cab429b 100644 --- a/addons/web/static/src/core/domain_selector_dialog/domain_selector_dialog.js +++ b/addons/web/static/src/core/domain_selector_dialog/domain_selector_dialog.js @@ -53,6 +53,7 @@ DomainSelectorDialog.props = { defaultLeafValue: { type: Array, optional: true }, initialValue: { type: String, optional: true }, onSelected: { type: Function, optional: true }, + text: { type: String, optional: true }, }; DomainSelectorDialog.defaultProps = { initialValue: "", diff --git a/addons/web/static/src/core/domain_selector_dialog/domain_selector_dialog.xml b/addons/web/static/src/core/domain_selector_dialog/domain_selector_dialog.xml index 74ab5939996..923066f2c4d 100644 --- a/addons/web/static/src/core/domain_selector_dialog/domain_selector_dialog.xml +++ b/addons/web/static/src/core/domain_selector_dialog/domain_selector_dialog.xml @@ -3,6 +3,7 @@ +
diff --git a/addons/web/static/src/core/select_menu/select_menu.js b/addons/web/static/src/core/select_menu/select_menu.js index 513110d18e0..1aed04b605b 100644 --- a/addons/web/static/src/core/select_menu/select_menu.js +++ b/addons/web/static/src/core/select_menu/select_menu.js @@ -18,6 +18,8 @@ export class SelectMenu extends Component { class: "", togglerClass: "", onSelect: () => {}, + required: false, + searchable: true, searchPlaceholder: _lt("Search..."), choices: [], groups: [], @@ -57,6 +59,8 @@ export class SelectMenu extends Component { }, class: { type: String, optional: true }, togglerClass: { type: String, optional: true }, + required: { type: Boolean, optional: true }, + searchable: { type: Boolean, optional: true }, searchPlaceholder: { type: String, optional: true }, value: { optional: true }, onSelect: { type: Function, optional: true }, @@ -116,7 +120,7 @@ export class SelectMenu extends Component { } canClear() { - return this.props.value != null; + return !this.props.required && this.props.value != null; } onInput(searchString) { diff --git a/addons/web/static/src/core/select_menu/select_menu.xml b/addons/web/static/src/core/select_menu/select_menu.xml index bddf66afd55..0616aa26704 100644 --- a/addons/web/static/src/core/select_menu/select_menu.xml +++ b/addons/web/static/src/core/select_menu/select_menu.xml @@ -5,7 +5,7 @@ -
+
{ }); QUnit.test( - "Clear button calls 'onSelect' with null value and appears only when value is null", + "Clear button calls 'onSelect' with null value and appears only when value is not null", async (assert) => { class Parent extends Component { setup() { @@ -214,6 +214,40 @@ QUnit.module("Web Components", (hooks) => { } ); + QUnit.test( + "When the \"required\" props is set to true, the clear button is not shown", + async (assert) => { + class Parent extends Component { + setup() { + this.state = useState({ value: null }); + this.choices = [ + { label: "Hello", value: "hello" }, + { label: "World", value: "world" }, + ]; + } + setValue(newValue) { + this.state.value = newValue; + } + } + Parent.components = { SelectMenu }; + Parent.template = xml` + + `; + + const parent = await mount(Parent, target, { env }); + assert.containsNone(target, ".o_select_menu_toggler_clear", 'When the value is not set, there is no "clear" button'); + + parent.setValue("hello"); + await nextTick(); + assert.strictEqual(getValue(), "Hello"); + assert.containsNone(target, ".o_select_menu_toggler_clear", 'When the value is set, there is no "clear" button'); + } + ); + QUnit.test("Items are sorted based on their label", async (assert) => { class Parent extends Component { setup() {