diff --git a/src/Field.ts b/src/Field.ts index fbb2295..e53e830 100644 --- a/src/Field.ts +++ b/src/Field.ts @@ -117,6 +117,14 @@ class Field extends Widget { this._selectionValues = value; } + /** + * Base type of the field + */ + _fieldType: string = ""; + get fieldType(): string { + return this._fieldType; + } + constructor(props: any) { super(props); @@ -128,6 +136,10 @@ class Field extends Widget { this._id = props.name; } + if (props.type) { + this._fieldType = props.fieldsWidgetType; + } + if (props.activated) { this._activated = props.activated; } diff --git a/src/Form.ts b/src/Form.ts index 56fd2ee..069872f 100644 --- a/src/Form.ts +++ b/src/Form.ts @@ -291,7 +291,7 @@ class Form { * Calls container's findById method to find the widgets matching with param id * @param {string} id id to find */ - findById(id: string): Widget | null { + findById(id: string): Field | Widget | null { return this.container.findById(id); } } diff --git a/src/spec/Form.spec.ts b/src/spec/Form.spec.ts index e659314..e562169 100644 --- a/src/spec/Form.spec.ts +++ b/src/spec/Form.spec.ts @@ -273,6 +273,15 @@ describe("A Form", () => { expect(form.findById("char1")).toBeInstanceOf(Char); }); + it("should return the type when the widget is defined", () => { + const form = new Form(FIELDS); + form.parse(XML_VIEW_FORM); + const emailField = form.findById("email") as Field; + expect(emailField.type).toBe("email"); + expect(emailField).toBeInstanceOf(Char); + expect(emailField.fieldType).toBe("char"); + }); + it("should return undefined when a widget is not found by id", () => { const fields = { char1: { size: 128, string: "Name", type: "char", views: {} },