From 21374cc41a60d5136dc5bc430665eef4712b4b3d Mon Sep 17 00:00:00 2001 From: Jorge Pinna Puissant Date: Mon, 7 Nov 2022 14:34:13 +0000 Subject: [PATCH] [FIX] web: form_compiler, classes on FormLabel in a group Before this commit, when compiling a form group, the scope class is added to the elements of the outer group. It was added on the element class attribute. The issue is that FormLabel don't have a class attribute but a className attribute. So the class wasn't shown on the DOM. Now, the class is added on the FormLabel className attribute and shown in the DOM. closes odoo/odoo#105315 X-original-commit: 214beb39d7c1a315255f0a5a842e60f73e7900cc Signed-off-by: Aaron Bohy (aab) Co-authored-by: Lucas Perais (lpe) --- .../static/src/views/form/form_compiler.js | 28 ++++++++++++------ .../tests/views/form/form_compiler_tests.js | 2 +- .../tests/views/form/form_view_tests.js | 29 +++++++++++++++++++ .../settings_form_view_tests.js | 2 +- 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/addons/web/static/src/views/form/form_compiler.js b/addons/web/static/src/views/form/form_compiler.js index fa91858e63d..234d63f0eda 100644 --- a/addons/web/static/src/views/form/form_compiler.js +++ b/addons/web/static/src/views/form/form_compiler.js @@ -70,13 +70,6 @@ export class FormCompiler extends ViewCompiler { } createLabelFromField(fieldId, fieldName, fieldString, label, params) { - const props = { - id: `'${fieldId}'`, - fieldName: `'${fieldName}'`, - record: `props.record`, - fieldInfo: `props.archInfo.fieldNodes['${fieldId}']`, - className: `"${label.className}"`, - }; let labelText = label.textContent || fieldString; if (label.hasAttribute("data-no-label")) { labelText = toStringExpression(""); @@ -86,7 +79,11 @@ export class FormCompiler extends ViewCompiler { : `props.record.fields['${fieldName}'].string`; } const formLabel = createElement("FormLabel", { - "t-props": objectToString(props), + id: `'${fieldId}'`, + fieldName: `'${fieldName}'`, + record: `props.record`, + fieldInfo: `props.archInfo.fieldNodes['${fieldId}']`, + className: `"${label.className}"`, string: labelText, }); const condition = label.getAttribute("t-if"); @@ -372,7 +369,20 @@ export class FormCompiler extends ViewCompiler { const groupClassExpr = `scope && scope.className`; if (isComponentNode(slotContent)) { - if (getTag(child, true) !== "button") { + if (getTag(slotContent) === "FormLabel") { + mainSlot.prepend( + createElement("t", { + "t-set": "addClass", + "t-value": groupClassExpr, + }) + ); + combineAttributes( + slotContent, + "className", + `(addClass ? " " + addClass : "")`, + `+` + ); + } else if (getTag(child, true) !== "button") { if (slotContent.hasAttribute("class")) { mainSlot.prepend( createElement("t", { 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 1e116f06ac8..956ff99af4b 100644 --- a/addons/web/static/tests/views/form/form_compiler_tests.js +++ b/addons/web/static/tests/views/form/form_compiler_tests.js @@ -54,7 +54,7 @@ QUnit.module("Form Compiler", (hooks) => {
- +
`; assert.areEquivalent(compileTemplate(arch), expected); 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 2e0425c0606..e1a91c70175 100644 --- a/addons/web/static/tests/views/form/form_view_tests.js +++ b/addons/web/static/tests/views/form/form_view_tests.js @@ -826,6 +826,35 @@ QUnit.module("Views", (hooks) => { assert.containsOnce(target, "div.o_inner_group"); }); + QUnit.test("group with formLabel", async function (assert) { + await makeView({ + type: "form", + resModel: "partner", + serverData, + arch: ` +
+ + + + + + +
`, + resId: 1, + }); + assert.hasClass(target.querySelector(".o_field_widget[name=foo]"), "o_field_char"); + assert.hasClass(target.querySelector(".o_field_widget[name=foo]"), "col-lg-6"); + + assert.hasClass(target.querySelector(".o_form_label[for=foo]"), "plop"); + assert.hasClass(target.querySelector(".o_form_label[for=foo]"), "plop2"); + assert.hasClass(target.querySelector(".o_form_label[for=foo]"), "col-lg-6"); + }); + QUnit.test("group containing both a field and a group", async function (assert) { // The purpose of this test is to check that classnames defined in a // field widget and those added by the form renderer are correctly 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 82188392611..ec2b2ff83d9 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 @@ -1455,7 +1455,7 @@ QUnit.module("SettingsFormView", (hooks) => {
- +