@@ -131,7 +131,7 @@ export class FormHelpersService {
131
131
for ( const name of questionsToUpload ) {
132
132
const files = temporaryFilesStorage [ name ] ;
133
133
if ( ! isNil ( files ) ) {
134
- for ( const [ index , file ] of files . entries ( ) ) {
134
+ for ( const [ , file ] of files . entries ( ) ) {
135
135
// Upload the file using document management system
136
136
if ( useDocumentManagement ) {
137
137
// Avoid already uploaded ones checking if contains an itemId
@@ -148,33 +148,37 @@ export class FormHelpersService {
148
148
question
149
149
) ;
150
150
if ( driveId && itemId ) {
151
- const fileContent = data [ name ] [ index ] . content ;
152
- data [ name ] [ index ] . content = {
153
- driveId,
154
- itemId,
155
- } ;
156
-
157
- // Check if any other question is using the same file
158
- survey . getAllQuestions ( ) . forEach ( ( question ) => {
159
- const questionType = question . getType ( ) ;
160
- if (
161
- questionType !== 'file' ||
162
- // Only change files that are not in the temporary storage
163
- // meaning their values came from the default values
164
- ! ! temporaryFilesStorage [ question . name ]
165
- ) {
166
- return ;
167
- }
168
- const files = data [ question . name ] ?? [ ] ;
169
- files . forEach ( ( file : any ) => {
170
- if ( file && file . content === fileContent ) {
171
- file . content = {
172
- driveId,
173
- itemId,
174
- } ;
151
+ const matchingFile = data [ name ] . find (
152
+ ( x : any ) => x . name === file . name
153
+ ) ;
154
+ if ( matchingFile ) {
155
+ const fileContent = matchingFile . content ;
156
+ matchingFile . content = {
157
+ driveId,
158
+ itemId,
159
+ } ;
160
+ // Check if any other question is using the same file
161
+ survey . getAllQuestions ( ) . forEach ( ( question ) => {
162
+ const questionType = question . getType ( ) ;
163
+ if (
164
+ questionType !== 'file' ||
165
+ // Only change files that are not in the temporary storage
166
+ // meaning their values came from the default values
167
+ ! ! temporaryFilesStorage [ question . name ]
168
+ ) {
169
+ return ;
175
170
}
171
+ const files = data [ question . name ] ?? [ ] ;
172
+ files . forEach ( ( file : any ) => {
173
+ if ( file && file . content === fileContent ) {
174
+ file . content = {
175
+ driveId,
176
+ itemId,
177
+ } ;
178
+ }
179
+ } ) ;
176
180
} ) ;
177
- } ) ;
181
+ }
178
182
}
179
183
} catch ( error ) {
180
184
failedFilesToUpload . push ( { question : name , file } ) ;
@@ -188,28 +192,33 @@ export class FormHelpersService {
188
192
formId
189
193
) ) as string ;
190
194
if ( path ) {
191
- const fileContent = data [ name ] [ index ] . content ;
192
- data [ name ] [ index ] . content = path ;
195
+ const matchingFile = data [ name ] . find (
196
+ ( x : any ) => x . name === file . name
197
+ ) ;
198
+ if ( matchingFile ) {
199
+ const fileContent = matchingFile . content ;
200
+ matchingFile . content = path ;
193
201
194
- // Check if any other question is using the same file
195
- survey . getAllQuestions ( ) . forEach ( ( question ) => {
196
- const questionType = question . getType ( ) ;
197
- if (
198
- questionType !== 'file' ||
199
- // Only change files that are not in the temporary storage
200
- // meaning their values came from the default values
201
- ! ! temporaryFilesStorage [ question . name ]
202
- ) {
203
- return ;
204
- }
205
-
206
- const files = data [ question . name ] ?? [ ] ;
207
- files . forEach ( ( file : any ) => {
208
- if ( file && file . content === fileContent ) {
209
- file . content = path ;
202
+ // Check if any other question is using the same file
203
+ survey . getAllQuestions ( ) . forEach ( ( question ) => {
204
+ const questionType = question . getType ( ) ;
205
+ if (
206
+ questionType !== 'file' ||
207
+ // Only change files that are not in the temporary storage
208
+ // meaning their values came from the default values
209
+ ! ! temporaryFilesStorage [ question . name ]
210
+ ) {
211
+ return ;
210
212
}
213
+
214
+ const files = data [ question . name ] ?? [ ] ;
215
+ files . forEach ( ( file : any ) => {
216
+ if ( file && file . content === fileContent ) {
217
+ file . content = path ;
218
+ }
219
+ } ) ;
211
220
} ) ;
212
- } ) ;
221
+ }
213
222
}
214
223
}
215
224
}
0 commit comments