From f6ea833524a91dab134e3c190637541370b6c51f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20G=C3=BCell=20Segarra?= Date: Wed, 23 Oct 2024 14:46:59 +0200 Subject: [PATCH 1/3] fix: field domain should have priority over fields (#128) 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')]"); + }); }); From e927c43c01e20407613b51a03537dda8f02c0c84 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 23 Oct 2024 12:47:51 +0000 Subject: [PATCH 2/3] chore(release): 2.13.1 [skip ci] ## [2.13.1](https://github.com/gisce/ooui/compare/v2.13.0...v2.13.1) (2024-10-23) ### Bug Fixes * field domain should have priority over fields ([#128](https://github.com/gisce/ooui/issues/128)) ([f6ea833](https://github.com/gisce/ooui/commit/f6ea833524a91dab134e3c190637541370b6c51f)) --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1e1b54d..9b4709f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@gisce/ooui", - "version": "2.13.0", + "version": "2.13.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@gisce/ooui", - "version": "2.13.0", + "version": "2.13.1", "dependencies": { "@gisce/conscheck": "1.0.9", "html-entities": "^2.3.3", diff --git a/package.json b/package.json index b1b73d4..bd2e34f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gisce/ooui", - "version": "2.13.0", + "version": "2.13.1", "engines": { "node": "20.5.0" }, From c540ea68e2ffba168084d70954883ee619774b24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gu=CC=88ell=20Segarra?= Date: Wed, 23 Oct 2024 17:14:08 +0200 Subject: [PATCH 3/3] fix: adjust fallback widget type to field https://github.com/gisce/webclient/issues/1320 --- src/WidgetFactory.ts | 8 ++++++-- src/spec/Form.spec.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/WidgetFactory.ts b/src/WidgetFactory.ts index 864cf1e..e8fcb7c 100644 --- a/src/WidgetFactory.ts +++ b/src/WidgetFactory.ts @@ -11,7 +11,6 @@ import Many2one from "./Many2one"; import Markdown from "./Markdown"; import Boolean from "./Boolean"; import Integer from "./Integer"; -import Widget from "./Widget"; import Float from "./Float"; import FloatTime from "./FloatTime"; import HTMLPreview from "./HTMLPreview"; @@ -38,6 +37,7 @@ import Avatar from "./Avatar"; import Time from "./Time"; import Alert from "./Alert"; import Comments from "./Comments"; +import Field from "./Field"; class WidgetFactory { /** @@ -179,6 +179,8 @@ class WidgetFactory { } createWidget(type: string, props: any) { + this._widgetClass = undefined; + let finalType = type; this.setWidgetClass(type); @@ -190,7 +192,9 @@ class WidgetFactory { } if (this._widgetClass === undefined) { - this._widgetClass = Widget; + // Last fallback, with Field widget and original type from xml + finalType = type; + this._widgetClass = Field; } // TODO: Widget Class constructors should use only the props needed, not all props. diff --git a/src/spec/Form.spec.ts b/src/spec/Form.spec.ts index 27eec07..f724edf 100644 --- a/src/spec/Form.spec.ts +++ b/src/spec/Form.spec.ts @@ -5852,4 +5852,32 @@ describe("A Form", () => { const field_char = form.findById("field_char"); expect(field_char!.domain!).toBe("[('value', '=', 'form')]"); }); + it.only("a field with no supported type should fallback to field generic widget", () => { + const fields = { + field_char: { + digits: [16, 2], + is_function: true, + readonly: 1, + string: "Etapa", + type: "json", + views: {}, + widget: "arrow_steps", + }, + }; + const xmlViewForm = ` +
+ + `; + const form = new Form(fields); + form.parse(xmlViewForm, { + values: { + field_char: "test", + }, + }); + + const field_char = form.findById("field_char") as Field; + expect(field_char).toBeDefined(); + expect(field_char?.type).toBe("arrow_steps"); + expect(field_char?.id).toBe("field_char"); + }); });