Skip to content

Commit

Permalink
fix: adjust fallback widget type to field
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed Oct 23, 2024
1 parent e927c43 commit c540ea6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
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 @@ -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 = `<?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 c540ea6

Please sign in to comment.