Skip to content

Commit 7a43de4

Browse files
committed
Merge branch 'ravichandran-blog-v2-dev' into v2-dev
2 parents 8965c86 + 7959f63 commit 7a43de4

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

docs/documentation/docs/controls/DynamicForm.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This control can dynamically generate SharePoint list or SharePoint document lib
88
- Import the following modules to your component:
99

1010
```TypeScript
11-
import { DynamicForm } from "fx-controls-react/lib/DynamicForm";
11+
import { DynamicForm } from "@pnp/spfx-controls-react/lib/DynamicForm";
1212
```
1313

1414
- Use the DynamicForm control in your code as follows:
@@ -38,6 +38,7 @@ The `DynamicForm` can be configured with the following properties:
3838
| contentTypeId | string | no | content type ID |
3939
| disabled | boolean | no | Option allow to be enable or disable. Default value is `false`|
4040
| onBeforeSubmit | (listItemData: any) => Promise<boolean> | no | Before submit handler. Allows to modify the object to be submitted or cancel the submission. |
41-
| onSubmitted | (listItem: any) => void | no | Method that returns listItem data JSON object. |
41+
| onSubmitted | (listItemData: any, listItem?: IItem) => void | no | Method that returns listItem data JSON object and PnPJS list item instance (`IItem`). |
4242
| onSubmitError | (listItemData: any, error: Error) => void | no | Handler of submission error. |
4343
| onCancelled | () => void | no | Handler when form has been cancelled. |
44+
| returnListItemInstanceOnSubmit | boolean | no | Specifies if `onSubmitted` event should pass PnPJS list item (`IItem`) as a second parameter. Default - `true` |

src/controls/dynamicForm/DynamicForm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
189189
try {
190190
const iur = await sp.web.lists.getById(listId).items.getById(listItemId).update(objects);
191191
if (onSubmitted) {
192-
onSubmitted(iur.data);
192+
onSubmitted(iur.data, this.props.returnListItemInstanceOnSubmit !== false ? iur.item : undefined);
193193
}
194194
}
195195
catch (error) {
@@ -204,7 +204,7 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
204204
try {
205205
const iar = await sp.web.lists.getById(listId).items.add(objects);
206206
if (onSubmitted) {
207-
onSubmitted(iar.data);
207+
onSubmitted(iar.data, this.props.returnListItemInstanceOnSubmit !== false ? iar.item : undefined);
208208
}
209209
}
210210
catch (error) {

src/controls/dynamicForm/IDynamicFormProps.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ExtensionContext } from '@microsoft/sp-extension-base';
22
import { WebPartContext } from '@microsoft/sp-webpart-base';
3+
import { IItem } from '@pnp/sp/items';
34

45
export interface IDynamicFormProps {
56
/**
@@ -22,7 +23,7 @@ export interface IDynamicFormProps {
2223
/**
2324
* Handler for form submitted event
2425
*/
25-
onSubmitted?: (listItemData: any) => void;
26+
onSubmitted?: (listItemData: any, listItem?: IItem) => void;
2627
/**
2728
* Handler of submission error
2829
*/
@@ -39,6 +40,12 @@ export interface IDynamicFormProps {
3940
* Content type id of the item
4041
*/
4142
contentTypeId?: string;
43+
44+
/**
45+
* Specifies if onSubmitted event should pass PnPJS list item (IItem) as a second parameter. Default - true
46+
*/
47+
returnListItemInstanceOnSubmit?: boolean;
48+
4249
/**
4350
* Used to execute WebSearch. If not provided SearchTab will not be available.
4451
*/

0 commit comments

Comments
 (0)