Skip to content

richTextFieldToInputSchema

richTextFieldToInputSchema(props): ZodType

Defined in: packages/core/src/fields/richtext/inputSchema.ts:42

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

Checks shape only, not Plate’s full node catalogue: every array item is either an element ({ type: string, children: [...] }, recursive) or an inline leaf ({ text: string }), with every other key passed through unchanged — Plate attaches feature-specific props (url, bold, mediaId, …) to the same nodes, and this schema only needs to agree with Plate on the two keys core actually reads (richTextToPlainText’s text/children). This keeps core independent of whichever editor adapter is configured.

required means at least one node’s accumulated plain text (richTextToPlainText) is non-empty — a document holding only empty paragraphs is shape-valid but fails the required check, the same way an empty string fails text()’s required check (CORE-1). Richtext has no own ignoreRequired parameter: it is a leaf field type like uploadFieldToInputSchema, not a group/array/blocks container with sub-fields to recurse into — a draft-lenient pass reaches it the same way it reaches upload, via adminFieldToInputSchema’s own { ...field, required: false } override before dispatch (wired when this field joins that switch in Step 3).

Input props.

RichTextField

The resolved richtext field definition.

ZodType

A Zod array schema with optionality and the required content check applied.

const field = richtext({ required: true })
richTextFieldToInputSchema({ field })
// rejects [], [{ type: "p", children: [{ text: "" }] }]
// accepts [{ type: "p", children: [{ text: "Hello" }] }]