Skip to content

Commit

Permalink
fix: fixed issue where zod or yup schema would not validate in formdi…
Browse files Browse the repository at this point in the history
…alog
  • Loading branch information
Pagebakers committed Oct 26, 2023
1 parent 5589d3b commit 1c64bfa
Show file tree
Hide file tree
Showing 4 changed files with 1,242 additions and 212 deletions.
6 changes: 6 additions & 0 deletions .changeset/friendly-forks-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@saas-ui/forms': patch
'@saas-ui/react': patch
---

Fixed issue where Zod or Yup schemas would not validate in FormDialog
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ import { FormDialog } from '@saas-ui/forms/zod'
import * as z from 'zod'

const schema = z.object({
title: z.string().describe('Title'),
title: z.string().nonempty().describe('Title'),
description: z.string().optional().describe('Description'),
})

Expand Down
12 changes: 9 additions & 3 deletions packages/saas-ui-forms/src/create-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,19 @@ export function createForm<FieldDefs>({
props: WithFields<FormProps<TSchema, TFieldValues, TContext>, FieldDefs>,
ref: ForwardedRef<HTMLFormElement>
) => {
const { schema, ...rest } = props
const {
schema,
resolver: resolverProp,
fieldResolver: fieldResolverProp,
...rest
} = props

return (
<FieldsProvider value={fields || {}}>
<Form
ref={ref}
resolver={resolver?.(props.schema)}
fieldResolver={fieldResolver?.(schema)}
resolver={resolverProp ?? resolver?.(props.schema)}
fieldResolver={fieldResolverProp ?? fieldResolver?.(schema)}
{...rest}
/>
</FieldsProvider>
Expand Down
Loading

0 comments on commit 1c64bfa

Please sign in to comment.