@@ -21,19 +21,38 @@ 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
+
34
+ sp . setup ( {
35
+ sp : {
36
+ headers : {
37
+ Accept : "application/json;odata=verbose" ,
38
+ } ,
39
+ baseUrl : this . props . webAbsoluteUrl
40
+ } ,
41
+ } ) ;
42
+ } else {
43
+ sp . setup ( {
44
+ spfxContext : this . props . context
45
+ } ) ;
46
+
47
+ }
48
+
31
49
// Initialize state
32
50
this . state = {
33
51
fieldCollection : [ ]
34
52
} ;
35
53
// Get SPService Factory
36
- this . _spService = new SPservice ( this . props . context ) ;
54
+ this . _spService = this . props . webAbsoluteUrl ? new SPservice ( this . props . context , this . props . webAbsoluteUrl ) : new SPservice ( this . props . context ) ;
55
+
37
56
}
38
57
39
58
/**
@@ -58,10 +77,15 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
58
77
{ fieldCollection . map ( ( v , i ) => {
59
78
return < DynamicField { ...v } disabled = { v . disabled || isSaving } /> ;
60
79
} ) }
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 >
80
+ {
81
+ ! this . props . disabled &&
82
+ < Stack className = { styles . buttons } horizontal tokens = { stackTokens } >
83
+ < PrimaryButton disabled = { isSaving } text = { strings . Save } onClick = { ( ) => this . onSubmitClick ( ) } />
84
+ < DefaultButton disabled = { isSaving } text = { strings . Cancel } onClick = { this . props . onCancelled } />
85
+ </ Stack >
86
+ }
87
+
88
+
65
89
</ div >
66
90
}
67
91
</ div >
@@ -303,7 +327,7 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
303
327
let defaultContentType = await spList . contentTypes . select ( "Id" , "Name" ) . get ( ) ;
304
328
contentTypeId = defaultContentType [ 0 ] [ "Id" ] . StringValue ;
305
329
}
306
- const listFeilds = await this . getFormFields ( listId , contentTypeId , context . pageContext . web . absoluteUrl ) ;
330
+ const listFeilds = await this . getFormFields ( listId , contentTypeId , this . webURL ) ;
307
331
const tempFields : IDynamicFieldProps [ ] = [ ] ;
308
332
let order : number = 0 ;
309
333
const responseValue = listFeilds [ 'value' ] ;
@@ -340,7 +364,7 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
340
364
lookupListId = field [ "LookupList" ] ;
341
365
lookupField = field [ "LookupField" ] ;
342
366
if ( item !== null ) {
343
- defaultValue = await this . _spService . getLookupValue ( listId , listItemId , field . InternalName , context . pageContext . web . absoluteUrl ) ;
367
+ defaultValue = await this . _spService . getLookupValue ( listId , listItemId , field . InternalName , this . webURL ) ;
344
368
}
345
369
else {
346
370
defaultValue = [ ] ;
@@ -351,14 +375,14 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
351
375
lookupListId = field [ "LookupList" ] ;
352
376
lookupField = field [ "LookupField" ] ;
353
377
if ( item !== null ) {
354
- defaultValue = await this . _spService . getLookupValues ( listId , listItemId , field . InternalName , context . pageContext . web . absoluteUrl ) ;
378
+ defaultValue = await this . _spService . getLookupValues ( listId , listItemId , field . InternalName , this . webURL ) ;
355
379
}
356
380
else {
357
381
defaultValue = [ ] ;
358
382
}
359
383
}
360
384
else if ( fieldType === "TaxonomyFieldTypeMulti" ) {
361
- let response = await this . _spService . getTaxonomyFieldInternalName ( this . props . listId , field . InternalName , this . props . context . pageContext . web . absoluteUrl ) ;
385
+ let response = await this . _spService . getTaxonomyFieldInternalName ( this . props . listId , field . InternalName , this . webURL ) ;
362
386
hiddenName = response [ "value" ] ;
363
387
termSetId = field [ "TermSetId" ] ;
364
388
if ( item !== null ) {
@@ -414,7 +438,7 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
414
438
}
415
439
else if ( fieldType === "UserMulti" ) {
416
440
if ( item !== null )
417
- defaultValue = await this . _spService . getUsersUPNFromFieldValue ( listId , listItemId , field . InternalName , context . pageContext . web . absoluteUrl ) ;
441
+ defaultValue = await this . _spService . getUsersUPNFromFieldValue ( listId , listItemId , field . InternalName , this . webURL ) ;
418
442
else {
419
443
defaultValue = [ ] ;
420
444
}
@@ -423,7 +447,7 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
423
447
}
424
448
else if ( fieldType === "Thumbnail" ) {
425
449
if ( defaultValue !== null ) {
426
- defaultValue = context . pageContext . web . absoluteUrl . split ( '/sites/' ) [ 0 ] + JSON . parse ( defaultValue ) . serverRelativeUrl ;
450
+ defaultValue = this . webURL . split ( '/sites/' ) [ 0 ] + JSON . parse ( defaultValue ) . serverRelativeUrl ;
427
451
}
428
452
}
429
453
else if ( fieldType === "User" ) {
@@ -517,7 +541,7 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
517
541
const {
518
542
context
519
543
} = this . props ;
520
- const webAbsoluteUrl = ! webUrl ? context . pageContext . web . absoluteUrl : webUrl ;
544
+ const webAbsoluteUrl = ! webUrl ? this . webURL : webUrl ;
521
545
let apiUrl = '' ;
522
546
if ( contentTypeId !== undefined && contentTypeId !== '' ) {
523
547
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