Skip to content

Commit 3e3ed74

Browse files
authored
Merge pull request #186 from workfloworchestrator/2175-floris-fixes
2175: Fixes resetting form data with empty forms
2 parents 35a7467 + 2ed0d10 commit 3e3ed74

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

frontend/packages/pydantic-forms/src/core/hooks/hooks.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ describe('getZodValidationObject', () => {
184184
},
185185
});
186186

187-
it('Returns undefined when no properties are passed', () => {
187+
it('Returns empty ZodObject when no properties are passed', () => {
188188
const zodObject = getZodValidationObject({}, getMockMatcher());
189-
const expectedZodObject = z.any();
189+
const expectedZodObject = z.object();
190190
expect(z.toJSONSchema(zodObject)).toEqual(
191191
z.toJSONSchema(expectedZodObject),
192192
);

frontend/packages/pydantic-forms/src/core/hooks/useGetZodSchema.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ export const getZodValidationObject = (
8282
properties,
8383
componentMatcherExtender,
8484
);
85+
8586
if (!pydanticFormComponents || pydanticFormComponents.length === 0)
86-
return z.any();
87+
return z.object();
8788

8889
const validationObject: { [k: string]: z.ZodTypeAny } = {};
8990
pydanticFormComponents.forEach((component) => {
@@ -104,7 +105,7 @@ export const getZodValidationObject = (
104105

105106
validationObject[id] = zodRule ?? z.any();
106107
});
107-
return validationObject ? z.object(validationObject) : z.any();
108+
return validationObject ? z.object(validationObject) : z.object();
108109
};
109110

110111
export const useGetZodSchema = (
@@ -113,8 +114,9 @@ export const useGetZodSchema = (
113114
): ZodObject | ZodAny => {
114115
return useMemo(() => {
115116
if (!pydanticFormSchema) {
116-
return z.any();
117+
return z.object();
117118
}
119+
118120
// Get all fields ids including the nested ones to generate the correct validation schema
119121
const validationObject = getZodValidationObject(
120122
pydanticFormSchema.properties,

0 commit comments

Comments
 (0)