[FIX] web: display fewer for m2x autocomplete menu

In legacy, an m2x autocomplete would not display extra lines
received from the server inside the dropdown menu.

This commit reintroduce that behavior as it was lost in the
wowl conversion.

closes odoo/odoo#102954

X-original-commit: 1b2686aeadfac97f060a07de86e5a0eb2051eee2
Signed-off-by: Mathieu Duckerts-Antoine <dam@odoo.com>
This commit is contained in:
Bruno Boi
2022-10-10 19:55:25 +02:00
parent ed57d1cfad
commit b82787b4ea
2 changed files with 63 additions and 1 deletions
@@ -223,7 +223,7 @@ export class Many2XAutocomplete extends Component {
const options = records.map((result) => ({
value: result[0],
label: result[1],
label: result[1].split("\n")[0],
}));
if (this.props.quickCreate && request.length) {
@@ -1321,6 +1321,68 @@ QUnit.module("Fields", (hooks) => {
assert.verifySteps(["search: ", "search: ", "search: p", "search: p"]);
});
QUnit.test("many2one search with server returning multiple lines", async function (assert) {
const namegets = {
2: "fizz\nbuzz\nfizzbuzz",
4: "aaa\nAAA\nRecord",
};
await makeView({
type: "form",
resModel: "partner",
resId: 1,
serverData,
arch: `
<form>
<sheet>
<group>
<field name="trululu" options="{'always_reload': 1}" />
</group>
</sheet>
</form>`,
mockRPC(route, { args, kwargs, method }) {
if (method === "name_get") {
assert.step(method);
return args.map((id) => [id, namegets[id]]);
}
if (method === "name_search") {
assert.step(method);
return Object.keys(namegets).map((id) => [id, namegets[id]]);
}
},
});
assert.verifySteps(["name_get"]);
const input = target.querySelector(".o_field_widget input");
// Initial value
assert.strictEqual(input.value, "aaa");
assert.strictEqual(
target.querySelector(".o_field_many2one_extra").innerHTML,
"<span>AAA</span><br><span>Record</span>"
);
// Change the value
await editInput(input, null, "fizz");
// should display only the first line of the returned value from the server
assert.verifySteps(["name_search"]);
assert.deepEqual(
[...target.querySelectorAll(".dropdown-menu li:not(.o_m2o_dropdown_option")].map(
(el) => el.textContent
),
["fizz", "aaa"]
);
await click(target.querySelector(".dropdown-menu li"));
// Check the selection has been taken into account
assert.verifySteps(["name_get"]);
assert.strictEqual(input.value, "fizz");
assert.strictEqual(
target.querySelector(".o_field_many2one_extra").innerHTML,
"<span>buzz</span><br><span>fizzbuzz</span>"
);
});
QUnit.test("many2one search with trailing and leading spaces", async function (assert) {
await makeView({
type: "form",