Skip to content

Commit dfc57ce

Browse files
committed
cherry-pick 7959f63
1 parent ec9c37c commit dfc57ce

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

docs/documentation/docs/controls/DynamicForm.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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,4 +1,5 @@
11
import { BaseComponentContext } from '@microsoft/sp-component-base';
2+
import { IItem } from '@pnp/sp/items';
23

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

0 commit comments

Comments
 (0)