Skip to content

Commit

Permalink
Merge branch 'feature/add-field-type' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed Nov 8, 2024
2 parents 15c1148 + 0f3da71 commit 5419882
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/Field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/spec/Form.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {} },
Expand Down

0 comments on commit 5419882

Please sign in to comment.