Skip to content

Commit 9ab659b

Browse files
authored
Merge pull request #47 from workfloworchestrator/1719-fixes
1719: Adds better way to reset at the end of a form
2 parents 9c26306 + 366993b commit 9ab659b

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ const RenderForm = (contextProps: PydanticFormContextProps) => {
2727
headerComponent,
2828
skipSuccessNotice,
2929
loadingComponent,
30-
clearForm,
3130
} = contextProps;
3231
const {
3332
formRenderer,
3433
footerRenderer,
3534
componentMatcher: customComponentMatcher,
36-
resetAfterSubmit,
3735
} = config || {};
3836

3937
const LoadingComponent = loadingComponent ?? (
@@ -49,10 +47,6 @@ const RenderForm = (contextProps: PydanticFormContextProps) => {
4947
}
5048

5149
if (isFullFilled) {
52-
if (resetAfterSubmit) {
53-
clearForm();
54-
}
55-
5650
if (skipSuccessNotice) {
5751
return <></>;
5852
}

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ function PydanticFormContextProvider({
156156
mode: 'all',
157157
});
158158

159+
// Adds watch subscripton on form values
159160
useEffect(() => {
160161
const sub = rhf.watch((values) => {
161162
setSaveToLeavePageInCurrentState(false);
@@ -181,18 +182,22 @@ function PydanticFormContextProvider({
181182
*/
182183
// handle successfull submits
183184
useEffect(() => {
184-
if (!isFullFilled || !onSuccess) {
185+
if (!isFullFilled) {
185186
return;
186187
}
187-
const values = rhf.getValues();
188-
189-
if (skipSuccessNotice) {
190-
onSuccess(values, apiResponse || {});
191-
} else {
192-
setTimeout(() => {
193-
onSuccess?.(values, apiResponse || {});
194-
}, 1500); // Delay to allow notice to show first
188+
189+
if (onSuccess) {
190+
const values = rhf.getValues();
191+
if (skipSuccessNotice) {
192+
onSuccess(values, apiResponse || {});
193+
} else {
194+
setTimeout(() => {
195+
onSuccess?.(values, apiResponse || {});
196+
}, 1500); // Delay to allow notice to show first
197+
}
195198
}
199+
200+
rhf.reset();
196201
}, [apiResponse, isFullFilled, onSuccess, rhf, skipSuccessNotice]);
197202

198203
// a useeffect for whenever the error response updates
@@ -367,4 +372,5 @@ export function usePydanticFormContext() {
367372

368373
return context;
369374
}
375+
370376
export default PydanticFormContextProvider;

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ export interface PydanticFormContextProps {
7575
formKey: string;
7676
formIdKey?: string;
7777
clearForm: () => void;
78-
resetAfterSubmit?: boolean;
7978
}
8079

8180
export enum PydanticFormState {
@@ -308,8 +307,6 @@ export interface PydanticFormsContextConfig {
308307

309308
// have an option to change the layout columns of fields
310309
formStructureMutator?: PydanticFormStructureMutator;
311-
312-
resetAfterSubmit?: boolean;
313310
}
314311

315312
export type FormRenderer = React.JSXElementConstructor<{

0 commit comments

Comments
 (0)