From d8d1eea44b9d9088dedde21650ace33e279d2078 Mon Sep 17 00:00:00 2001 From: Jorge Pinna Puissant Date: Thu, 1 Sep 2022 10:54:19 +0000 Subject: [PATCH] [FIX] web: form_compiler, do not link field and label with technical ID Before this commit, on compiling the field, a search is done to find the label to link to the field. To do this search, the following field's attributes were used: the `id`, which is encoded on the arch of the view; if the `id` wasn't set, the `field_id`, which is an internal technical attribute, is used, and if neither of these were set, the 'name', which is also encoded on the arch, attribute is used. These attributes are compared with the content of the `for` attribute on the label. The issue with this, is that as the `field_id` is an internal technical attribute and could never be found on the view arch, neither on the content of the `for` attribute on the label. Leading to empty labels, or labels linked to the wrong fields. This principally occurs when two fields with the same name are found on the view. Now, only the `id` attribute and the `name` attribute, which both can be found on the view arch, are going to be used to search the correct label to link to it's corresponding fields. closes odoo/odoo#99399 Signed-off-by: Aaron Bohy (aab) --- .../static/src/views/form/form_compiler.js | 2 +- .../tests/views/form/form_view_tests.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) 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",