urlFieldToInputSchema
urlFieldToInputSchema(
props):ZodType
Defined in: packages/core/src/fields/url/inputSchema.ts:45
Builds a Zod schema for validating a URL field value in the admin form.
Required fields check emptiness before URL format:
z.string({ error: "This field is required." }).min(1, "This field is required.").pipe(z.url()) — the .min(1) stage runs on the plain string
and short-circuits the pipe, so an empty required field reports “This
field is required.” instead of “Invalid URL” (CORE-2; previously
z.url().min(1, ...) ran the format check first, and new URL("")
always threw before .min() ever ran). Required fields never receive
.default() — unlike text(), the url field has no implicit
empty-string default even when non-required. .default(field.defaultValue)
is applied only for non-required fields with an explicit defaultValue.
Wraps in .optional() for non-required fields via
applyBaseInputSchemaMeta.
field.min/field.max (character-length constraints) are composed onto
the same z.string() chain, before .pipe(z.url()), so a too-short or
too-long value reports the length message rather than “Invalid URL”.
Pinned, unchanged behaviour (verified before and after this fix):
z.url() trims whitespace, imposes no protocol restriction (mailto:/
ftp:// pass), and requires an absolute URL.
Parameters
Section titled “Parameters”Input props.
The resolved URL field definition.
Returns
Section titled “Returns”ZodType
A Zod URL schema. Optional fields are wrapped in .optional(). A
.default() is only added when field.defaultValue is not undefined.
Example
Section titled “Example”// Required — rejects a missing/empty value with "This field is required.", not "Invalid URL"urlFieldToInputSchema({ field: url({ required: true }) })
// Optional with explicit defaulturlFieldToInputSchema({ field: url({ required: false, defaultValue: "https://example.com" }) })// → z.union([z.url(), z.literal("")]).default("https://example.com")