From 545e2378ab4e0cb472a5881a2159a113236d5b0a Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Tue, 23 Aug 2022 08:56:53 +0000 Subject: [PATCH] [FIX] web: render label with empty string to preserve layout Previously, when a label in a form arch had an empty string attribute, we would not render it at all as it seemed useless. In practice, some existing form arch rely on empty labels being rendered for layout reasons, and the corresponding views are now broken. This commit fixes that by instead rendering an empty label, just as legacy views used to. Part-of: odoo/odoo#98711 --- .../static/src/views/form/form_compiler.js | 13 +++++----- .../tests/views/form/form_compiler_tests.js | 16 ++++++++----- .../tests/views/form/form_view_tests.js | 24 +++++++++++-------- .../settings_form_view_tests.js | 3 ++- 4 files changed, 33 insertions(+), 23 deletions(-) diff --git a/addons/web/static/src/views/form/form_compiler.js b/addons/web/static/src/views/form/form_compiler.js index cfdc71d85dd..bed508d254d 100644 --- a/addons/web/static/src/views/form/form_compiler.js +++ b/addons/web/static/src/views/form/form_compiler.js @@ -79,13 +79,14 @@ export class FormCompiler extends ViewCompiler { fieldInfo: `props.archInfo.fieldNodes['${fieldId}']`, className: `"${label.className}"`, }; - if (label.hasAttribute("data-no-label")) { - return; - } let labelText = label.textContent || fieldString; - labelText = labelText - ? toStringExpression(labelText) - : `props.record.fields['${fieldName}'].string`; + if (label.hasAttribute("data-no-label")) { + labelText = toStringExpression(""); + } else { + labelText = labelText + ? toStringExpression(labelText) + : `props.record.fields['${fieldName}'].string`; + } const formLabel = createElement("FormLabel", { "t-props": objectToString(props), string: labelText, diff --git a/addons/web/static/tests/views/form/form_compiler_tests.js b/addons/web/static/tests/views/form/form_compiler_tests.js index 3f4a09d60fe..93a85da3e7c 100644 --- a/addons/web/static/tests/views/form/form_compiler_tests.js +++ b/addons/web/static/tests/views/form/form_compiler_tests.js @@ -41,16 +41,20 @@ QUnit.module("Form Compiler", () => { assert.areEquivalent(compileTemplate(arch), expected); }); - QUnit.test("label with empty string is not rendered", async (assert) => { - const arch = /*xml*/ `