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*/ `
`;
- const expected = /*xml*/ `
+ QUnit.test(
+ "label with empty string compiles to FormLabel with empty string",
+ async (assert) => {
+ const arch = /*xml*/ ``;
+ const expected = /*xml*/ `
-
+
+
`;
- assert.areEquivalent(compileTemplate(arch), expected);
- });
+ assert.areEquivalent(compileTemplate(arch), expected);
+ }
+ );
QUnit.test("properly compile simple div with field", async (assert) => {
const arch = /*xml*/ ``;
diff --git a/addons/web/static/tests/views/form/form_view_tests.js b/addons/web/static/tests/views/form/form_view_tests.js
index 90ba5bf1830..6fdbcafd90f 100644
--- a/addons/web/static/tests/views/form/form_view_tests.js
+++ b/addons/web/static/tests/views/form/form_view_tests.js
@@ -1690,12 +1690,14 @@ QUnit.module("Views", (hooks) => {
assert.strictEqual(target.querySelector("label.o_form_label").textContent, "Bar");
});
- QUnit.test("label with empty string attribute doesn't get rendered", async function (assert) {
- await makeView({
- type: "form",
- resModel: "partner",
- serverData,
- arch: `
+ QUnit.test(
+ "label with empty string attribute renders to an empty label",
+ async function (assert) {
+ await makeView({
+ type: "form",
+ resModel: "partner",
+ serverData,
+ arch: `
`,
- resId: 2,
- });
+ resId: 2,
+ });
- assert.containsNone(target, "label.o_form_label");
- });
+ assert.containsOnce(target, "label.o_form_label");
+ assert.equal(target.querySelector("label.o_form_label").textContent, "");
+ }
+ );
QUnit.test(
"label is not rendered when invisible and not at top-level in a group",
diff --git a/addons/web/static/tests/webclient/settings_form_view/settings_form_view_tests.js b/addons/web/static/tests/webclient/settings_form_view/settings_form_view_tests.js
index 952f9af8bf7..0bef908a1ec 100644
--- a/addons/web/static/tests/webclient/settings_form_view/settings_form_view_tests.js
+++ b/addons/web/static/tests/webclient/settings_form_view/settings_form_view_tests.js
@@ -599,7 +599,8 @@ QUnit.module("SettingsFormView", (hooks) => {
const webClient = await createWebClient({ serverData });
await doAction(webClient, 1);
- assert.containsNone(target, ".o_form_label");
+ assert.containsOnce(target, ".o_form_label");
+ assert.equal(target.querySelector(".o_form_label").textContent, "");
assert.containsNone(target, ".settingSearchHeader");
await editSearch(target, "Fo");
await execTimeouts();