diff --git a/package-lock.json b/package-lock.json index d95530a..9b4709f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@gisce/ooui", - "version": "2.14.0-alpha.1", + "version": "2.13.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@gisce/ooui", - "version": "2.14.0-alpha.1", + "version": "2.13.1", "dependencies": { "@gisce/conscheck": "1.0.9", "html-entities": "^2.3.3", diff --git a/package.json b/package.json index fac3860..bd2e34f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gisce/ooui", - "version": "2.14.0-alpha.1", + "version": "2.13.1", "engines": { "node": "20.5.0" }, 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 c1656ca..7ccdfbd 100644 --- a/src/spec/Form.spec.ts +++ b/src/spec/Form.spec.ts @@ -5975,4 +5975,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"); + }); });