From 460ba28d057a0d28ea9777652bbc0405a0ff7bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gu=CC=88ell=20Segarra?= Date: Wed, 23 Oct 2024 13:31:01 +0200 Subject: [PATCH] fix: field domain should have priority over fields https://github.com/gisce/webclient/issues/1317 --- src/Form.ts | 6 +++--- src/spec/Form.spec.ts | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Form.ts b/src/Form.ts index 5e94b8f..56fd2ee 100644 --- a/src/Form.ts +++ b/src/Form.ts @@ -240,9 +240,9 @@ class Form { if (checkIfDomainHasValue(tagAttributes.domain)) { domain = tagAttributes.domain; - } - - if (checkIfDomainHasValue(this._fields[tagAttributes.name]?.domain)) { + } else if ( + checkIfDomainHasValue(this._fields[tagAttributes.name]?.domain) + ) { domain = this._fields[tagAttributes.name].domain; } diff --git a/src/spec/Form.spec.ts b/src/spec/Form.spec.ts index b93e71c..27eec07 100644 --- a/src/spec/Form.spec.ts +++ b/src/spec/Form.spec.ts @@ -5831,4 +5831,25 @@ describe("A Form", () => { // expect(pageAutoconsum).toBeDefined(); // expect(pageAutoconsum.invisible).toBeTruthy(); // }); + it("a domain defined in the xml should have priority over the domain defined in the fields", () => { + const fields = { + field_char: { + type: "char", + domain: "[('value', '=', 'field')]", + }, + }; + const xmlViewForm = ` +
+ + `; + const form = new Form(fields); + form.parse(xmlViewForm, { + values: { + field_char: "test", + }, + }); + + const field_char = form.findById("field_char"); + expect(field_char!.domain!).toBe("[('value', '=', 'form')]"); + }); });