[FIX] web: Many2One in list: keeps input after record create
Have a many2one in an editable list view. Type something in the input and click on "Create and edit". Confirm the record creation in the modal. Before this commit, the input of the field disappears. After this commit, the input stays. closes odoo/odoo#99480 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -146,7 +146,15 @@ export class Many2XAutocomplete extends Component {
|
||||
fieldString,
|
||||
onClose: () => {
|
||||
const autoCompleteInput = autoCompleteContainer.el.querySelector("input");
|
||||
autoCompleteInput.value = "";
|
||||
|
||||
// There are two cases:
|
||||
// 1. Value is the same as the input: it means the autocomplete has re-rendered with the right value
|
||||
// This is in case we saved the record, triggering all the interface to update.
|
||||
// 2. Value is different from the input: it means the input has a manually entered value and nothing
|
||||
// happened, that is, we discarded the changes
|
||||
if (this.props.value !== autoCompleteInput.value) {
|
||||
autoCompleteInput.value = "";
|
||||
}
|
||||
autoCompleteInput.focus();
|
||||
},
|
||||
});
|
||||
|
||||
@@ -669,6 +669,54 @@ QUnit.module("Fields", (hooks) => {
|
||||
assert.strictEqual($("tr.o_data_row").length, 0, "should display 0 records");
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"many2ones in list views: create in dialog keeps the input",
|
||||
async function (assert) {
|
||||
serverData.views = {
|
||||
"partner,false,form": `
|
||||
<form>
|
||||
<field name="name" />
|
||||
</form>`,
|
||||
};
|
||||
|
||||
await makeView({
|
||||
type: "list",
|
||||
resModel: "partner",
|
||||
serverData,
|
||||
arch: `
|
||||
<tree editable="top">
|
||||
<field name="trululu" />
|
||||
</tree>`,
|
||||
mockRPC(route, args) {
|
||||
if (args.method === "create" || args.method === "write") {
|
||||
assert.step(`${args.method}: ${JSON.stringify(args.args)}`);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
await click(target.querySelectorAll(".o_data_cell")[0]);
|
||||
const input = target.querySelector(".o_field_widget[name=trululu] input");
|
||||
input.value = "yy";
|
||||
await triggerEvent(input, null, "input");
|
||||
await click(target, ".o_field_widget[name=trululu] input");
|
||||
await selectDropdownItem(target, "trululu", "Create and edit...");
|
||||
|
||||
await clickSave(target.querySelector(".modal"));
|
||||
assert.verifySteps([`create: [{"name":"yy"}]`]);
|
||||
assert.strictEqual(
|
||||
target.querySelector(".o_field_widget[name=trululu] input").value,
|
||||
"yy"
|
||||
);
|
||||
|
||||
await click(target);
|
||||
assert.verifySteps([`write: [[1],{"trululu":5}]`]);
|
||||
assert.strictEqual(
|
||||
target.querySelector(".o_data_cell[name=trululu]").textContent,
|
||||
"yy"
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
QUnit.test(
|
||||
"onchanges on many2ones trigger when editing record in form view",
|
||||
async function (assert) {
|
||||
|
||||
Reference in New Issue
Block a user