Skip to content

Commit 48dd842

Browse files
authored
Merge pull request #59 from workfloworchestrator/1848-multiple-step-bug
1848: Replace instead of add form data after an error
2 parents cbe0574 + 2b8d6a1 commit 48dd842

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,18 @@ function PydanticFormContextProvider({
111111
});
112112
};
113113

114-
const addFormInputData = (formInput: object) => {
115-
setFormInputData((currentInputs) => {
116-
updateHistory(formInput, currentInputs);
117-
return [...currentInputs, formInput];
118-
});
119-
};
114+
const addFormInputData = useCallback(
115+
(formInput: object, replaceInsteadOfAdd = false) => {
116+
setFormInputData((currentInputs) => {
117+
const data = replaceInsteadOfAdd
118+
? currentInputs.slice(0, -1)
119+
: currentInputs;
120+
updateHistory(formInput, data);
121+
return [...data, formInput];
122+
});
123+
},
124+
[],
125+
);
120126

121127
const [errorDetails, setErrorDetails] =
122128
useState<PydanticFormValidationErrorDetails>();
@@ -289,10 +295,10 @@ function PydanticFormContextProvider({
289295

290296
const submitFormFn = useCallback(() => {
291297
setIsSending(true);
292-
addFormInputData(rhf?.getValues());
298+
addFormInputData(rhf?.getValues(), !!errorDetails);
293299

294300
window.scrollTo(0, 0);
295-
}, [rhf]);
301+
}, [rhf, errorDetails, addFormInputData]);
296302

297303
const onClientSideError = useCallback(
298304
(data?: FieldValues) => {

0 commit comments

Comments
 (0)