Skip to content

Commit aa0d51b

Browse files
authored
Merge pull request #162 from workfloworchestrator/2067-fix-restoring-errors
2067 fix restoring errors
2 parents f43c3e3 + e70319b commit aa0d51b

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
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+
Fix restoring values after an error

frontend/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,21 @@ const RenderForm = (contextProps: PydanticFormContextProps) => {
2727
skipSuccessNotice,
2828
loadingComponent,
2929
rhf,
30+
errorDetails,
31+
formInputData,
3032
} = contextProps;
3133

3234
const { formRenderer, footerRenderer, headerRenderer } = config || {};
3335

3436
useEffect(() => {
35-
if (rhf.getValues().length !== 0) {
36-
// Only trigger validations if there are values
37-
rhf.trigger();
37+
if (errorDetails) {
38+
// If we have an array restore the values
39+
const lastValues = [...formInputData].pop();
40+
rhf.reset({
41+
...lastValues,
42+
});
3843
}
39-
}, [rhf, pydanticFormSchema]);
44+
}, [errorDetails, formInputData]);
4045

4146
const pydanticFormComponents: PydanticFormComponents =
4247
getPydanticFormComponents(

0 commit comments

Comments
 (0)