[FIX] web: handle focus for buttons cells in list

This is reproducible in lots of ways, here's one:
- Inventory -> Products -> Any storable product
- Click on Update Quantity
- Click on the cell where the 'History' and 'Set' button are

This raises a traceback as the `cell` assigned right before is null at
that point. Indeed, since those cells from a special kind of column made
of buttons (o_list_buttons), those don't have a `name` attribute to
find, hence the traceback.

closes odoo/odoo#128014

X-original-commit: 222dc64be51cc8e711278cff96392e755ba39fd4
Signed-off-by: Francois Georis (fge) <fge@odoo.com>
This commit is contained in:
clesgow
2023-07-11 09:10:24 +02:00
parent e410bed643
commit 51de4ab9b5
2 changed files with 26 additions and 1 deletions
@@ -1040,7 +1040,7 @@ export class ListRenderer extends Component {
const cell = this.tableRef.el.querySelector(
`.o_selected_row td[name='${column.name}']`
);
if (containsActiveElement(cell)) {
if (cell && containsActiveElement(cell)) {
this.lastEditedCell = { column, record };
// Cell is already focused.
return;
@@ -8239,6 +8239,31 @@ QUnit.module("Views", (hooks) => {
);
});
QUnit.test("click on a button cell in a list view", async (assert) => {
serverData.models.foo.records[0].foo = "bar";
await makeView({
type: "list",
resModel: "foo",
serverData,
arch: `
<tree editable="bottom" limit="1">
<field name="foo"/>
<button name="action_do_something" type="object" string="Action"/>
</tree>`,
});
// Need to set the line in edition.
await click(target, "td[name=foo]");
assert.strictEqual(window.getSelection().toString(), "bar");
await click(target.querySelector(".o_data_cell.o_list_button"));
assert.strictEqual(
window.getSelection().toString(),
"bar",
"Focus should have returned to the editable cell without throwing an error"
);
});
QUnit.test("click on a button in a list view", async function (assert) {
assert.expect(10);