[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) <aab@odoo.com>
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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: `
|
||||
<form>
|
||||
<sheet>
|
||||
<field name="qux" invisible="1"/>
|
||||
<label for="qux"/>
|
||||
<field name="qux"/>
|
||||
</sheet>
|
||||
</form>`,
|
||||
resId: 1,
|
||||
});
|
||||
|
||||
assert.containsOnce(target, "label:contains(Qux)");
|
||||
});
|
||||
|
||||
QUnit.test("invisible elements are properly hidden", async function (assert) {
|
||||
await makeView({
|
||||
type: "form",
|
||||
|
||||
Reference in New Issue
Block a user