@@ -82,7 +82,7 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
82
82
{ fieldCollection . length === 0 ? < div > < ProgressIndicator label = { strings . DynamicFormLoading } description = { strings . DynamicFormPleaseWait } /> </ div > :
83
83
< div >
84
84
{ fieldCollection . map ( ( v , i ) => {
85
- if ( fieldOverrides && Object . prototype . hasOwnProperty . call ( fieldOverrides , v . columnInternalName ) ) {
85
+ if ( fieldOverrides && Object . prototype . hasOwnProperty . call ( fieldOverrides , v . columnInternalName ) ) {
86
86
v . disabled = v . disabled || isSaving ;
87
87
return fieldOverrides [ v . columnInternalName ] ( v ) ;
88
88
}
@@ -222,9 +222,11 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
222
222
}
223
223
224
224
// If we have the item ID, we simply need to update it
225
+ let newETag : string | undefined = undefined ;
225
226
if ( listItemId ) {
226
227
try {
227
- const iur = await sp . web . lists . getById ( listId ) . items . getById ( listItemId ) . update ( objects ) ;
228
+ const iur = await sp . web . lists . getById ( listId ) . items . getById ( listItemId ) . update ( objects , this . state . etag ) ;
229
+ newETag = iur . data [ 'odata.etag' ] ;
228
230
if ( onSubmitted ) {
229
231
onSubmitted ( iur . data , this . props . returnListItemInstanceOnSubmit !== false ? iur . item : undefined ) ;
230
232
}
@@ -239,58 +241,59 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
239
241
}
240
242
// Otherwise, depending on the content type ID of the item, if any, we need to behave accordingly
241
243
else if ( contentTypeId === undefined || contentTypeId === '' || ! contentTypeId . startsWith ( '0x0120' ) ) {
242
- // We are adding a new list item
243
- try {
244
- const iar = await sp . web . lists . getById ( listId ) . items . add ( objects ) ;
245
- if ( onSubmitted ) {
246
- onSubmitted ( iar . data , this . props . returnListItemInstanceOnSubmit !== false ? iar . item : undefined ) ;
247
- }
248
- }
249
- catch ( error ) {
250
- if ( onSubmitError ) {
251
- onSubmitError ( objects , error ) ;
252
- }
253
- console . log ( "Error" , error ) ;
254
- }
255
- } else if ( contentTypeId . startsWith ( '0x0120' ) ) {
256
- // We are adding a folder or a Document Set
257
- try {
258
- const idField = 'ID' ;
259
- const titleField = 'Title' ;
260
- const contentTypeIdField = 'ContentTypeId' ;
261
-
262
- const library = await sp . web . lists . getById ( listId ) ;
263
- const folderTitle = ( objects [ titleField ] !== undefined && objects [ titleField ] !== '' ) ?
264
- ( objects [ titleField ] as string ) . replace ( / [ " | * | : | < | > | ? | / | \\ | | ] / g, "_" ) : // Replace not allowed chars in folder name
265
- '' ; // Empty string will be replaced by SPO with Folder Item ID
266
- const newFolder = await library . rootFolder . addSubFolderUsingPath ( folderTitle ) ;
267
- const fields = await newFolder . listItemAllFields ( ) ;
268
- if ( fields [ idField ] ) {
269
-
270
- // Read the ID of the just created folder or Document Set
271
- const folderId = fields [ idField ] ;
272
-
273
- // Set the content type ID for the target item
274
- objects [ contentTypeIdField ] = contentTypeId ;
275
- // Update the just created folder or Document Set
276
- const iur = await library . items . getById ( folderId ) . update ( objects ) ;
277
- if ( onSubmitted ) {
278
- onSubmitted ( iur . data , this . props . returnListItemInstanceOnSubmit !== false ? iur . item : undefined ) ;
279
- }
280
- } else {
281
- throw new Error ( 'Unable to read the ID of the just created folder or Document Set' ) ;
282
- }
244
+ // We are adding a new list item
245
+ try {
246
+ const iar = await sp . web . lists . getById ( listId ) . items . add ( objects ) ;
247
+ if ( onSubmitted ) {
248
+ onSubmitted ( iar . data , this . props . returnListItemInstanceOnSubmit !== false ? iar . item : undefined ) ;
249
+ }
250
+ }
251
+ catch ( error ) {
252
+ if ( onSubmitError ) {
253
+ onSubmitError ( objects , error ) ;
283
254
}
284
- catch ( error ) {
285
- if ( onSubmitError ) {
286
- onSubmitError ( objects , error ) ;
255
+ console . log ( "Error" , error ) ;
256
+ }
257
+ } else if ( contentTypeId . startsWith ( '0x0120' ) ) {
258
+ // We are adding a folder or a Document Set
259
+ try {
260
+ const idField = 'ID' ;
261
+ const titleField = 'Title' ;
262
+ const contentTypeIdField = 'ContentTypeId' ;
263
+
264
+ const library = await sp . web . lists . getById ( listId ) ;
265
+ const folderTitle = ( objects [ titleField ] !== undefined && objects [ titleField ] !== '' ) ?
266
+ ( objects [ titleField ] as string ) . replace ( / [ " | * | : | < | > | ? | / | \\ | | ] / g, "_" ) : // Replace not allowed chars in folder name
267
+ '' ; // Empty string will be replaced by SPO with Folder Item ID
268
+ const newFolder = await library . rootFolder . addSubFolderUsingPath ( folderTitle ) ;
269
+ const fields = await newFolder . listItemAllFields ( ) ;
270
+ if ( fields [ idField ] ) {
271
+
272
+ // Read the ID of the just created folder or Document Set
273
+ const folderId = fields [ idField ] ;
274
+
275
+ // Set the content type ID for the target item
276
+ objects [ contentTypeIdField ] = contentTypeId ;
277
+ // Update the just created folder or Document Set
278
+ const iur = await library . items . getById ( folderId ) . update ( objects ) ;
279
+ if ( onSubmitted ) {
280
+ onSubmitted ( iur . data , this . props . returnListItemInstanceOnSubmit !== false ? iur . item : undefined ) ;
287
281
}
288
- console . log ( "Error" , error ) ;
282
+ } else {
283
+ throw new Error ( 'Unable to read the ID of the just created folder or Document Set' ) ;
284
+ }
285
+ }
286
+ catch ( error ) {
287
+ if ( onSubmitError ) {
288
+ onSubmitError ( objects , error ) ;
289
289
}
290
+ console . log ( "Error" , error ) ;
291
+ }
290
292
}
291
293
292
294
this . setState ( {
293
- isSaving : false
295
+ isSaving : false ,
296
+ etag : newETag
294
297
} ) ;
295
298
} catch ( error ) {
296
299
if ( onSubmitError ) {
@@ -346,14 +349,20 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
346
349
347
350
//getting all the fields information as part of get ready process
348
351
private getFieldInformations = async ( ) : Promise < void > => {
349
- const { listId, listItemId, disabledFields } = this . props ;
352
+ const { listId, listItemId, disabledFields, respectETag } = this . props ;
350
353
let contentTypeId = this . props . contentTypeId ;
351
354
try {
352
355
const spList = await sp . web . lists . getById ( listId ) ;
353
356
let item = null ;
354
- if ( listItemId !== undefined && listItemId !== null && listItemId !== 0 )
357
+ let etag : string | undefined = undefined ;
358
+ if ( listItemId !== undefined && listItemId !== null && listItemId !== 0 ) {
355
359
item = await spList . items . getById ( listItemId ) . get ( ) ;
356
360
361
+ if ( respectETag !== false ) {
362
+ etag = item [ 'odata.etag' ] ;
363
+ }
364
+ }
365
+
357
366
if ( contentTypeId === undefined || contentTypeId === '' ) {
358
367
const defaultContentType = await spList . contentTypes . select ( "Id" , "Name" ) . get ( ) ;
359
368
contentTypeId = defaultContentType [ 0 ] . Id . StringValue ;
@@ -390,7 +399,7 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
390
399
}
391
400
if ( fieldType === 'Choice' || fieldType === 'MultiChoice' ) {
392
401
field . Choices . forEach ( element => {
393
- choices . push ( { key : element , text : element } ) ;
402
+ choices . push ( { key : element , text : element } ) ;
394
403
} ) ;
395
404
} else if ( fieldType === "Note" ) {
396
405
richText = field . RichText ;
@@ -418,15 +427,15 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
418
427
anchorId = field . AnchorId ;
419
428
if ( item !== null ) {
420
429
item [ field . InternalName ] . forEach ( element => {
421
- selectedTags . push ( { key : element . TermGuid , name : element . Label } ) ;
430
+ selectedTags . push ( { key : element . TermGuid , name : element . Label } ) ;
422
431
} ) ;
423
432
424
433
defaultValue = selectedTags ;
425
434
} else {
426
435
if ( defaultValue !== "" ) {
427
436
defaultValue . split ( / # | ; / ) . forEach ( element => {
428
437
if ( element . indexOf ( '|' ) !== - 1 )
429
- selectedTags . push ( { key : element . split ( '|' ) [ 1 ] , name : element . split ( '|' ) [ 0 ] } ) ;
438
+ selectedTags . push ( { key : element . split ( '|' ) [ 1 ] , name : element . split ( '|' ) [ 0 ] } ) ;
430
439
} ) ;
431
440
432
441
defaultValue = selectedTags ;
@@ -441,12 +450,12 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
441
450
if ( item !== null ) {
442
451
const response = await this . _spService . getSingleManagedMtadataLabel ( listId , listItemId , field . InternalName ) ;
443
452
if ( response ) {
444
- selectedTags . push ( { key : response . TermID , name : response . Label } ) ;
453
+ selectedTags . push ( { key : response . TermID , name : response . Label } ) ;
445
454
defaultValue = selectedTags ;
446
455
}
447
456
} else {
448
457
if ( defaultValue !== "" ) {
449
- selectedTags . push ( { key : defaultValue . split ( '|' ) [ 1 ] , name : defaultValue . split ( '|' ) [ 0 ] . split ( '#' ) [ 1 ] } ) ;
458
+ selectedTags . push ( { key : defaultValue . split ( '|' ) [ 1 ] , name : defaultValue . split ( '|' ) [ 0 ] . split ( '#' ) [ 1 ] } ) ;
450
459
defaultValue = selectedTags ;
451
460
}
452
461
}
@@ -523,7 +532,7 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
523
532
}
524
533
}
525
534
526
- this . setState ( { fieldCollection : tempFields } ) ;
535
+ this . setState ( { fieldCollection : tempFields , etag : etag } ) ;
527
536
//return arrayItems;
528
537
} catch ( error ) {
529
538
console . log ( `Error get field informations` , error ) ;
0 commit comments