[FIX] web: form: correctly handle empty buttonbox
Before this commit, a form view with an empty button box would produce a crash, in the ButtonBox component, because it assumed to have slots. This commit prevents this from happening as we no longer put a ButtonBox component in the template if there's nothing in it. closes odoo/odoo#95427 Signed-off-by: Samuel Degueldre <sad@odoo.com>
This commit is contained in:
committed by
Aaron Bohy
parent
fadf643f97
commit
162b42e4cd
@@ -123,12 +123,13 @@ export class FormCompiler extends ViewCompiler {
|
||||
el.classList.remove("oe_button_box");
|
||||
const buttonBox = createElement("ButtonBox");
|
||||
let slotId = 0;
|
||||
|
||||
let hasContent = false;
|
||||
for (const child of el.children) {
|
||||
const invisible = getModifier(child, "invisible");
|
||||
if (isAlwaysInvisible(invisible, params)) {
|
||||
continue;
|
||||
}
|
||||
hasContent = true;
|
||||
const mainSlot = createElement("t", {
|
||||
"t-set-slot": `slot_${slotId++}`,
|
||||
isVisible:
|
||||
@@ -140,7 +141,7 @@ export class FormCompiler extends ViewCompiler {
|
||||
append(buttonBox, mainSlot);
|
||||
}
|
||||
|
||||
return buttonBox;
|
||||
return hasContent ? buttonBox : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5721,6 +5721,22 @@ QUnit.module("Views", (hooks) => {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("empty button box", async function (assert) {
|
||||
await makeView({
|
||||
type: "form",
|
||||
resModel: "partner",
|
||||
serverData,
|
||||
arch: `
|
||||
<form>
|
||||
<div class="oe_button_box" name="button_box">
|
||||
</div>
|
||||
</form>`,
|
||||
resId: 2,
|
||||
});
|
||||
|
||||
assert.containsNone(target, ".o-form-buttonbox");
|
||||
});
|
||||
|
||||
QUnit.test("one2many default value creation", async function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user