diff --git a/addons/web/static/src/views/form/form_compiler.js b/addons/web/static/src/views/form/form_compiler.js index 19bad3c5cca..2709bcebfdc 100644 --- a/addons/web/static/src/views/form/form_compiler.js +++ b/addons/web/static/src/views/form/form_compiler.js @@ -184,7 +184,7 @@ export class FormCompiler extends ViewCompiler { const fieldName = el.getAttribute("name"); const fieldString = el.getAttribute("string"); const fieldId = el.getAttribute("field_id") || fieldName; - const labelsForAttr = el.getAttribute("id") || fieldId; + const labelsForAttr = el.getAttribute("id") || fieldName; const labels = this.getLabels(labelsForAttr); const dynamicLabel = (label) => { const formLabel = this.createLabelFromField( 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 270d27a7209..6dcbcad1fe4 100644 --- a/addons/web/static/tests/views/form/form_view_tests.js +++ b/addons/web/static/tests/views/form/form_view_tests.js @@ -909,6 +909,25 @@ QUnit.module("Views", (hooks) => { assert.hasClass(target.querySelectorAll(".o_form_label")[1], "c"); }); + QUnit.test("invisible fields are not used for the label generation", async function (assert) { + await makeView({ + type: "form", + resModel: "partner", + serverData, + arch: ` +
+ + + +
`, + resId: 1, + }); + + assert.containsOnce(target, "label:contains(Qux)"); + }); + QUnit.test("invisible elements are properly hidden", async function (assert) { await makeView({ type: "form",