vantezzen / auto-form

🌟 A React component that automatically creates a @shadcn/ui form based on a zod schema.
https://vantezzen.github.io/auto-form/
MIT License
2.76k stars 99 forks source link

Confirm password does not work #6

Closed hkbertoson closed 1 year ago

hkbertoson commented 1 year ago
const formSchema = z
    .object({
        password: z.string(),
        confirm: z.string(),
    })
    .refine((data) => data.password === data.confirm, {
        message: 'Passwords must match.',
        path: ['confirm'],
    });
            <AutoForm
                formSchema={formSchema}
                fieldConfig={{
                    password: {
                        inputProps: {
                            type: 'password',
                            placeholder: '••••••••',
                        },
                    },
                    confirm: {
                        inputProps: {
                            type: 'password',
                            placeholder: '••••••••',
                        },
                    },
                }}
            >

Throws this error

image
vantezzen commented 1 year ago

AutoForm didn't support top-level refinements and excepted the outer zod object to not be wrapped. I now updated it to support that.

The TypeScript type is still slightly wrong as it doesn't allow multiple levels of ZodEffects but the code does. TypeScript doesn't seem to like circular type definitions so I'll have to look into how to circumvent this.