@@ -21,19 +21,36 @@ const stackTokens: IStackTokens = { childrenGap: 20 };
21
21
* DynamicForm Class Control
22
22
*/
23
23
export class DynamicForm extends React . Component < IDynamicFormProps , IDynamicFormState > {
24
+
24
25
private _spService : SPservice ;
26
+ private webURL = this . props . webAbsoluteUrl ? this . props . webAbsoluteUrl : this . props . context . pageContext . web . absoluteUrl ;
27
+
25
28
constructor ( props : IDynamicFormProps ) {
26
29
super ( props ) ;
27
30
// Initialize pnp sp
28
- sp . setup ( {
29
- spfxContext : this . props . context
30
- } ) ;
31
+
32
+ if ( this . props . webAbsoluteUrl ) {
33
+ sp . setup ( {
34
+ sp : {
35
+ headers : {
36
+ Accept : "application/json;odata=verbose" ,
37
+ } ,
38
+ baseUrl : this . props . webAbsoluteUrl
39
+ } ,
40
+ } ) ;
41
+ } else {
42
+ sp . setup ( {
43
+ spfxContext : this . props . context
44
+ } ) ;
45
+ }
46
+
31
47
// Initialize state
32
48
this . state = {
33
49
fieldCollection : [ ]
34
50
} ;
35
51
// Get SPService Factory
36
- this . _spService = new SPservice ( this . props . context ) ;
52
+ this . _spService = this . props . webAbsoluteUrl ? new SPservice ( this . props . context , this . props . webAbsoluteUrl ) : new SPservice ( this . props . context ) ;
53
+
37
54
}
38
55
39
56
/**
@@ -58,10 +75,15 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
58
75
{ fieldCollection . map ( ( v , i ) => {
59
76
return < DynamicField { ...v } disabled = { v . disabled || isSaving } /> ;
60
77
} ) }
61
- < Stack className = { styles . buttons } horizontal tokens = { stackTokens } >
62
- < PrimaryButton disabled = { isSaving } text = { strings . Save } onClick = { ( ) => this . onSubmitClick ( ) } />
63
- < DefaultButton disabled = { isSaving } text = { strings . Cancel } onClick = { this . props . onCancelled } />
64
- </ Stack >
78
+ {
79
+ ! this . props . disabled &&
80
+ < Stack className = { styles . buttons } horizontal tokens = { stackTokens } >
81
+ < PrimaryButton disabled = { isSaving } text = { strings . Save } onClick = { ( ) => this . onSubmitClick ( ) } />
82
+ < DefaultButton disabled = { isSaving } text = { strings . Cancel } onClick = { this . props . onCancelled } />
83
+ </ Stack >
84
+ }
85
+
86
+
65
87
</ div >
66
88
}
67
89
</ div >
@@ -303,7 +325,7 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
303
325
let defaultContentType = await spList . contentTypes . select ( "Id" , "Name" ) . get ( ) ;
304
326
contentTypeId = defaultContentType [ 0 ] [ "Id" ] . StringValue ;
305
327
}
306
- const listFeilds = await this . getFormFields ( listId , contentTypeId , context . pageContext . web . absoluteUrl ) ;
328
+ const listFeilds = await this . getFormFields ( listId , contentTypeId , this . webURL ) ;
307
329
const tempFields : IDynamicFieldProps [ ] = [ ] ;
308
330
let order : number = 0 ;
309
331
const responseValue = listFeilds [ 'value' ] ;
@@ -340,7 +362,7 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
340
362
lookupListId = field [ "LookupList" ] ;
341
363
lookupField = field [ "LookupField" ] ;
342
364
if ( item !== null ) {
343
- defaultValue = await this . _spService . getLookupValue ( listId , listItemId , field . EntityPropertyName , lookupField , context . pageContext . web . absoluteUrl ) ;
365
+ defaultValue = await this . _spService . getLookupValue ( listId , listItemId , field . EntityPropertyName , lookupField , this . webURL ) ;
344
366
}
345
367
else {
346
368
defaultValue = [ ] ;
@@ -351,14 +373,14 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
351
373
lookupListId = field [ "LookupList" ] ;
352
374
lookupField = field [ "LookupField" ] ;
353
375
if ( item !== null ) {
354
- defaultValue = await this . _spService . getLookupValues ( listId , listItemId , field . EntityPropertyName , lookupField , context . pageContext . web . absoluteUrl ) ;
376
+ defaultValue = await this . _spService . getLookupValues ( listId , listItemId , field . EntityPropertyName , lookupField , this . webURL ) ;
355
377
}
356
378
else {
357
379
defaultValue = [ ] ;
358
380
}
359
381
}
360
382
else if ( fieldType === "TaxonomyFieldTypeMulti" ) {
361
- let response = await this . _spService . getTaxonomyFieldInternalName ( this . props . listId , field . InternalName , this . props . context . pageContext . web . absoluteUrl ) ;
383
+ let response = await this . _spService . getTaxonomyFieldInternalName ( this . props . listId , field . InternalName , this . webURL ) ;
362
384
hiddenName = response [ "value" ] ;
363
385
termSetId = field [ "TermSetId" ] ;
364
386
if ( item !== null ) {
@@ -414,7 +436,7 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
414
436
}
415
437
else if ( fieldType === "UserMulti" ) {
416
438
if ( item !== null )
417
- defaultValue = await this . _spService . getUsersUPNFromFieldValue ( listId , listItemId , field . InternalName , context . pageContext . web . absoluteUrl ) ;
439
+ defaultValue = await this . _spService . getUsersUPNFromFieldValue ( listId , listItemId , field . InternalName , this . webURL ) ;
418
440
else {
419
441
defaultValue = [ ] ;
420
442
}
@@ -423,7 +445,7 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
423
445
}
424
446
else if ( fieldType === "Thumbnail" ) {
425
447
if ( defaultValue !== null ) {
426
- defaultValue = context . pageContext . web . absoluteUrl . split ( '/sites/' ) [ 0 ] + JSON . parse ( defaultValue ) . serverRelativeUrl ;
448
+ defaultValue = this . webURL . split ( '/sites/' ) [ 0 ] + JSON . parse ( defaultValue ) . serverRelativeUrl ;
427
449
}
428
450
}
429
451
else if ( fieldType === "User" ) {
@@ -517,7 +539,7 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
517
539
const {
518
540
context
519
541
} = this . props ;
520
- const webAbsoluteUrl = ! webUrl ? context . pageContext . web . absoluteUrl : webUrl ;
542
+ const webAbsoluteUrl = ! webUrl ? this . webURL : webUrl ;
521
543
let apiUrl = '' ;
522
544
if ( contentTypeId !== undefined && contentTypeId !== '' ) {
523
545
apiUrl = `${ webAbsoluteUrl } /_api/web/lists(@listId)/contenttypes('${ contentTypeId } ')/fields?@listId=guid'${ encodeURIComponent ( listId ) } '&$filter=ReadOnlyField eq false and Hidden eq false and (FromBaseType eq false or StaticName eq 'Title')` ;
0 commit comments