Skip to content

urlFieldToInputSchema

urlFieldToInputSchema(props): ZodType

Defined in: packages/core/src/fields/url/inputSchema.ts:30

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

Enforces URL format via z.url(). Required fields add a .min(1) check. .default(field.defaultValue) is applied only when defaultValue is explicitly set on the field — unlike text(), the url field has no implicit empty-string default. Wraps in .optional() for non-required fields via applyBaseInputSchemaMeta.

Input props.

UrlField

The resolved URL field definition.

ZodType

A Zod URL schema. Optional fields are wrapped in .optional(). A .default() is only added when field.defaultValue is not undefined.

// Required — rejects empty string and non-URLs
urlFieldToInputSchema({ field: url({ required: true }) })
// → z.url().min(1, "This field is required.").optional() — no default
// Optional with explicit default
urlFieldToInputSchema({ field: url({ required: false, defaultValue: "https://example.com" }) })
// → z.url().default("https://example.com").optional()