Skip to content

Commit 7d3cda7

Browse files
authored
Merge pull request #150 from workfloworchestrator/2076-refresh-on-formkey-change
2076 refresh on formkey change
2 parents 008d6f6 + fecf9f1 commit 7d3cda7

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
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 form if formKey changes

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ function PydanticFormContextProvider({
7979
);
8080
const [formInputData, setFormInputData] = useState<object[]>([]);
8181

82+
const formRef = useRef<string>(formKey);
83+
84+
useEffect(() => {
85+
if (formKey !== formRef.current) {
86+
// When the formKey changes we need to reset the form input data
87+
setFormInputData([]);
88+
setFormInputHistory(new Map<string, object>());
89+
formRef.current = formKey;
90+
}
91+
}, [formKey]);
92+
8293
const updateHistory = async (
8394
formInput: object,
8495
previousSteps: object[],

0 commit comments

Comments
 (0)