Skip to content

Commit de4a4b6

Browse files
authored
Merge pull request #1259 from bjdekker/feat-dynamic-form-children
Added the possibility to override field rendering for individual field
2 parents 5a637a5 + 612884e commit de4a4b6

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/controls/dynamicForm/DynamicForm.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,18 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
6868
fieldCollection,
6969
isSaving
7070
} = this.state;
71+
72+
const fieldOverrides = this.props.fieldOverrides;
73+
7174
return (
7275
<div>
7376
{fieldCollection.length === 0 ? <div><ProgressIndicator label={strings.DynamicFormLoading} description={strings.DynamicFormPleaseWait} /></div> :
7477
<div>
7578
{fieldCollection.map((v, i) => {
79+
if(fieldOverrides?.hasOwnProperty(v.columnInternalName)) {
80+
v.disabled = v.disabled || isSaving;
81+
return fieldOverrides[v.columnInternalName](v);
82+
}
7683
return <DynamicField {...v} disabled={v.disabled || isSaving} />;
7784
})}
7885
{

src/controls/dynamicForm/IDynamicFormProps.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { BaseComponentContext } from '@microsoft/sp-component-base';
22
import { IItem } from '@pnp/sp/items';
3+
import React from 'react';
4+
import { IDynamicFieldProps } from './dynamicField';
35

46
export interface IDynamicFormProps {
57
/**
@@ -40,6 +42,10 @@ export interface IDynamicFormProps {
4042
*/
4143
contentTypeId?: string;
4244

45+
/**
46+
* Key value pair for fields you want to override. Key is the internal field name, value is the function to be called for the custom element to render
47+
*/
48+
fieldOverrides?: {[columnInternalName: string] : {(fieldProperties: IDynamicFieldProps): React.ReactElement<IDynamicFieldProps>}};
4349
/**
4450
* Specifies if onSubmitted event should pass PnPJS list item (IItem) as a second parameter. Default - true
4551
*/

0 commit comments

Comments
 (0)