Skip to content

Commit

Permalink
Develop (#67)
Browse files Browse the repository at this point in the history
* fix #43: stop navigation to disabled items with buttons

* fix #44: update change events

* fix #48: making spacing configurable

* enhancement #53: add support for icons

* fix #62: support for filedata for input file type

* fix #64: adding type for input mask

* cleanup linting

* fix build

* fix #66: file upload not working for section forms
  • Loading branch information
manojadams committed Apr 5, 2024
1 parent 3cfdc6f commit 4b8c6f6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/constants/common-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export interface IFormField {
isDisabled?: boolean;
isReadonly?: boolean;
options?: Array<IOption>;
file?: File; // for file type
files?: Array<File>; // for file type
validation?: IValidation;

Expand Down
20 changes: 12 additions & 8 deletions src/utils/FormUtil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,24 +147,28 @@ export default class FormUtils {
return newFormData;
}

static getBase64(file: File) {
static getBase64(file?: File) {
return new Promise((resolve, reject) => {
const fileReader = new FileReader();
fileReader.readAsDataURL(file);
fileReader.onload = () => resolve(fileReader.result);
fileReader.onerror = reject;
if (file) {
const fileReader = new FileReader();
fileReader.readAsDataURL(file);
fileReader.onload = () => resolve(fileReader.result);
fileReader.onerror = reject;
} else {
resolve(null);
}
});
}

static async getFormFieldValue(formField: IFormField) {
switch (formField.displayType) {
case CONTROLS.FILE:
if (formField.files && formField.files.length > 0) {
if (formField.file && formField.file instanceof File) {
return {
name: formField.value,
[formField.config?.blob ? "file" : "fileData"]: formField.config?.blob
? formField.files[0]
: await this.getBase64(formField.files[0])
? formField.file
: await this.getBase64(formField.file)
};
}
return null;
Expand Down

0 comments on commit 4b8c6f6

Please sign in to comment.