From f9208f74d6e1570b6f81d087d1a3a0aa8b02cee1 Mon Sep 17 00:00:00 2001 From: ZenMasterJacob20011 Date: Tue, 11 Jun 2024 09:16:47 -0500 Subject: [PATCH 1/2] fixed file component upload error when no defaults is set to true --- src/components/file/File.js | 2 +- src/components/file/File.unit.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/file/File.js b/src/components/file/File.js index 9ca3aebe98..63e0346495 100644 --- a/src/components/file/File.js +++ b/src/components/file/File.js @@ -744,7 +744,7 @@ export default class FileComponent extends Field { const fileWithSameNameUploading = this.filesToSync.filesToUpload .some(fileToSync => fileToSync.file?.name === file.name); - const fileWithSameNameUploaded = this.dataValue + const fileWithSameNameUploaded = this.dataValue && this.dataValue .some(fileStatus => fileStatus.originalName === file.name); return fileWithSameNameUploaded || fileWithSameNameUploading diff --git a/src/components/file/File.unit.js b/src/components/file/File.unit.js index 0a06811fc4..8c71d69e60 100644 --- a/src/components/file/File.unit.js +++ b/src/components/file/File.unit.js @@ -271,4 +271,10 @@ describe('File Component', () => { }, 100); }); }); + it('should not error on upload when noDefaults is set to true', () => { + return Formio.createForm(document.createElement('div'), comp2,{ noDefaults: true }).then((form)=>{ + const file = form.getComponent('file'); + return file.handleFilesToUpload([{ name: 'mypdf.pdf', size: 123123, type: 'application/pdf' }]); + }); + }); }); From afd813e6109e7b0bb439f2e1c75af44da6abcde6 Mon Sep 17 00:00:00 2001 From: ZenMasterJacob20011 Date: Mon, 17 Jun 2024 09:17:10 -0500 Subject: [PATCH 2/2] replace array.some with lodash.some --- src/components/file/File.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/file/File.js b/src/components/file/File.js index 63e0346495..08266c1c8c 100644 --- a/src/components/file/File.js +++ b/src/components/file/File.js @@ -744,8 +744,7 @@ export default class FileComponent extends Field { const fileWithSameNameUploading = this.filesToSync.filesToUpload .some(fileToSync => fileToSync.file?.name === file.name); - const fileWithSameNameUploaded = this.dataValue && this.dataValue - .some(fileStatus => fileStatus.originalName === file.name); + const fileWithSameNameUploaded = _.some(this.dataValue, fileStatus => fileStatus.originalName === file.name); return fileWithSameNameUploaded || fileWithSameNameUploading ? {