[FIX] web: X2many focus handle field

Before this commit, in an X2many in editable list mode with a handle
field, if you passed a record in edit mode, the handle field was focused.
The expected behaviour is to focus the first editable field.

Part-of: odoo/odoo#96101
This commit is contained in:
FrancoisGe
2022-07-28 01:29:58 +02:00
parent 87b8feee03
commit 857cbba5a1
2 changed files with 36 additions and 1 deletions
@@ -364,7 +364,7 @@ export class ListRenderer extends Component {
);
if (cell) {
const toFocus = getElementToFocus(cell);
if (toFocus) {
if (cell !== toFocus) {
this.focus(toFocus);
break;
}
@@ -3786,6 +3786,41 @@ QUnit.module("Fields", (hooks) => {
assert.hasClass(target.querySelectorAll(".o_data_row")[3], "o_selected_row");
});
QUnit.test(
"creating a new line in an o2m with an handle field does not focus the handler",
async function (assert) {
await makeView({
type: "form",
resModel: "partner",
serverData,
arch: `
<form>
<field name="turtles">
<tree editable="bottom">
<field name="turtle_int" widget="handle"/>
<field name="turtle_foo"/>
</tree>
</field>
</form>`,
resId: 2,
});
await clickEdit(target);
await addRow(target);
assert.strictEqual(
document.activeElement,
target.querySelector("[name='turtle_foo'] input")
);
triggerHotkey("Enter");
await nextTick();
assert.strictEqual(
document.activeElement,
target.querySelector("[name='turtle_foo'] input")
);
}
);
QUnit.test("editing a o2m, with required field and onchange", async function (assert) {
serverData.models.turtle.fields.turtle_foo.required = true;
delete serverData.models.turtle.fields.turtle_foo.default;