Skip to content

Commit 08ec42a

Browse files
authored
Merge pull request #145 from workfloworchestrator/2076-move-form-reset
2076 move form reset
2 parents 4b0fc23 + 569bcdf commit 08ec42a

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'pydantic-forms': patch
3+
---
4+
5+
Resets the form with initial data in useEffect after render

frontend/packages/pydantic-forms/src/components/render/RenderForm.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const RenderForm = (contextProps: PydanticFormContextProps) => {
2727
skipSuccessNotice,
2828
loadingComponent,
2929
rhf,
30+
initialData,
3031
} = contextProps;
3132
const { formRenderer, footerRenderer, headerRenderer } = config || {};
3233

@@ -37,6 +38,10 @@ const RenderForm = (contextProps: PydanticFormContextProps) => {
3738
}
3839
}, [rhf, pydanticFormSchema]);
3940

41+
useEffect(() => {
42+
rhf.reset(initialData);
43+
}, [rhf, initialData]);
44+
4045
const pydanticFormComponents: PydanticFormComponents =
4146
getPydanticFormComponents(
4247
pydanticFormSchema?.properties || {},

frontend/packages/pydantic-forms/src/core/PydanticFormContextProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ function PydanticFormContextProvider({
178178
const rhf = useForm({
179179
resolver: zodResolver(zodSchema),
180180
mode: 'all',
181-
values: initialData,
182181
});
183182

184183
const resetFormData = useCallback(
@@ -402,6 +401,7 @@ function PydanticFormContextProvider({
402401
clearForm,
403402
formInputData,
404403
hasNext,
404+
initialData,
405405
};
406406

407407
return (

frontend/packages/pydantic-forms/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export interface PydanticFormContextProps {
7777
clearForm: () => void;
7878
hasNext: boolean;
7979
formInputData: object[];
80+
initialData: FieldValues;
8081
}
8182

8283
export enum PydanticFormState {

0 commit comments

Comments
 (0)