Skip to content

textFieldToInputSchema

textFieldToInputSchema(props): ZodType

Defined in: packages/core/src/fields/text/inputSchema.ts:29

Builds a Zod schema for validating a text field value in the admin form.

Applies min/max character-length constraints by composing them onto the same schema chain built for required, rather than reassigning over it — a required field with min/max configured keeps every check (CORE-1). Required fields attach { error: "This field is required." } to the base z.string() call and add .min(1, "This field is required.") so a missing value and an explicit empty string report the same message; they never receive .default(), matching applyBaseInputSchemaMeta’s .optional() gate. Non-required fields keep .default(field.defaultValue).

Input props.

TextField

The resolved text field definition

ZodType

A Zod string schema with length constraints and optionality applied

const field = text({ required: true, min: 3, max: [100, "Too long."] })
textFieldToInputSchema({ field })
// → z.string({ error: "This field is required." }).min(1, "...").min(3, "...").max(100, "Too long.")