Fields

Text

One line or several lines of text, stored as a string.

text is one line, like a title or a name. textarea is several lines, like a short summary.

The text field in the admin
The textarea field in the admin

Example

cms/collections/posts.ts
export const posts = defineCollection({
  fields: {
    title: { type: "text", required: true, maxLength: 80 },
    summary: { type: "textarea", rows: 3, placeholder: "One or two sentences" },
  },
});

A read returns a string:

const post = await cms.findOne("posts", { where: { slug } });
post?.title; // string
post?.summary; // string | null | undefined

Render it

<h1>{post.title}</h1>
<p class="whitespace-pre-line">{post.summary}</p>
  • All three escape the text, so a value cannot inject HTML.
  • A textarea keeps its line breaks. white-space: pre-line shows them.

Prefix and suffix

prefix and suffix show fixed text around the input. They are not stored:

domain: { type: "text", prefix: "https://", suffix: ".com" },
The text-affixes field in the admin

Input mask

mask formats what the editor types. # is a digit, @ a letter and * either:

cardNumber: { type: "text", mask: "#### #### #### ####" },

The admin shows 4242 4242 4242 4242, but stores only the typed characters: 4242424242424242.

Pattern

pattern is a regular expression that MUST match the whole value:

zip: { type: "text", pattern: "\\d{5}" },

It is a string, not a RegExp, because the admin checks it too. It works like the HTML pattern attribute.

Options

text is one line. textarea is several lines.Shown in the empty input.The fewest characters. An empty optional value is not checked.The most characters.A regular expression for the whole value. In a textarea, only the server checks it.Fixed text in front of the input, like https://. Not stored.Fixed text after the input, like .com. Not stored.An input mask, like "#### #### #### ####". minLength, maxLength and pattern check the stored value, so only the server checks them. See Maska for the syntax.The height of the empty input in lines. It grows with the content. Default 8.