Skip to content

Commit

Permalink
Merge branch 'fix/adjust-fallback-widget-type' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed Oct 23, 2024
2 parents 0ee5851 + c540ea6 commit d3f7936
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gisce/ooui",
"version": "2.14.0-alpha.1",
"version": "2.13.1",
"engines": {
"node": "20.5.0"
},
Expand Down
8 changes: 6 additions & 2 deletions src/WidgetFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 {
/**
Expand Down Expand Up @@ -179,6 +179,8 @@ class WidgetFactory {
}

createWidget(type: string, props: any) {
this._widgetClass = undefined;

let finalType = type;

this.setWidgetClass(type);
Expand All @@ -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.
Expand Down
28 changes: 28 additions & 0 deletions src/spec/Form.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<?xml version="1.0"?>
<form string="Form1">
<field name="field_char" widget="arrow_steps" colspan="4" nolabel="1"/>
</form>`;
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");
});
});

0 comments on commit d3f7936

Please sign in to comment.