Skip to content

getCollectionInputSchema

getCollectionInputSchema(props): ZodObject<{[key: string]: ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>; }, $strip>

Defined in: packages/core/src/collections/utils.ts:65

Builds a Zod object schema for validating all fields in a collection.

Calls adminFieldToInputSchema for each field and combines the results into a z.object({...}). Used by useCollectionForm as the TanStack Form onSubmitAsync / onBlurAsync validator.

Input props.

CollectionConfig

The collection whose fields define the schema shape.

ZodObject<{[key: string]: ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>; }, $strip>

A z.object schema with one key per collection field.

const schema = getCollectionInputSchema({ collection: postsCollection })
// → z.object({ title: z.string().min(1), slug: z.string().min(3).max(100) })
schema.parse({ title: "Hello", slug: "hello" }) // passes