Skip to content

Commit fa8f712

Browse files
author
Ruben van Leeuwen
committed
1954: Fix bug where references to objects instead of the objects where added to formInputData
1 parent cadc77d commit fa8f712

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { FieldValues, useForm } from 'react-hook-form';
1616
import { Subscription } from 'react-hook-form/dist/utils/createSubject';
1717

1818
import i18next from 'i18next';
19+
import _ from 'lodash';
1920
import { z } from 'zod';
2021
import { zodI18nMap } from 'zod-i18n-map';
2122

@@ -309,7 +310,10 @@ function PydanticFormContextProvider({
309310

310311
const submitFormFn = useCallback(() => {
311312
setIsSending(true);
312-
addFormInputData(rhf?.getValues(), !!errorDetails);
313+
const rhfValues = rhf.getValues();
314+
// Note. If we don't use cloneDeep here we are adding a reference to the rhfValues
315+
// that changes on every change in the form and triggering effects before we want to.
316+
addFormInputData(_.cloneDeep(rhfValues), !!errorDetails);
313317
window.scrollTo(0, 0);
314318
}, [rhf, errorDetails, addFormInputData]);
315319

0 commit comments

Comments
 (0)