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.


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>
<template>
<h1>{{ post.title }}</h1>
<p class="whitespace-pre-line">{{ post.summary }}</p>
</template>
<>
<h1>{post.title}</h1>
<p className="whitespace-pre-line">{post.summary}</p>
</>
- All three escape the text, so a value cannot inject HTML.
- A
textareakeeps its line breaks.white-space: pre-lineshows them.
Prefix and suffix
prefix and suffix show fixed text around the input. They are not stored:
domain: { type: "text", prefix: "https://", suffix: ".com" },

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.textarea, only the server checks it.https://. Not stored..com. Not stored."#### #### #### ####". minLength, maxLength and pattern check the stored value, so only the server checks them. See Maska for the syntax.8.Every field type takes these options. See the fields overview for examples and validation.
label
string | { en, de, … }
The label in the admin. Defaults to the key. Pass an object to translate it.
description
string | { en, de, … }
Help text below the input.
required
boolean
The value MUST be present. A list needs at least one item.
default
value | ({ user, … }) => value
The value of a new document, when the field is missing. A plain value also fills the new form in the admin. A function, like
({ user }) => user?.id, runs on the server only.unique
boolean
No other document of the collection has the same value. See Validation .
validate
(value, args) => true | string
Your own check. See Your own checks .
condition
Condition
Show the field only when other values match. See Conditions .
private
boolean
Public reads leave the value out. Signed-in users and server code see it.
access
{ read, create, update }
Who can read and write this field. See Access control .
localized
false
In a localized collection, every field is stored per language. Localization .
false shares this field between languages. Only on top-level fields. See hooks
FieldHooks
Functions that run for this field on every write and read, before the collection's hooks. See Hooks .
hidden
boolean
Admin only
The admin does not show the input. The value still saves. Use it for values a hook sets.
readOnly
boolean
Admin only
The admin shows the input disabled. Code and hooks can still write it.
width
"1/4" | "1/3" | "1/2" | "2/3" | "3/4" | "full"
Admin only
The share of the row the field takes. Fields next to each other fill a row. In a narrow form, every field takes the full width. Default
"full".separator
true | string
Admin only
A line above the field, to break up a long form. A string adds a heading above the line.
tab
string | string[]
Admin only
The tab that shows this field. Define the tabs with
tabs on the collection, global, group or list item.fieldset
string
Admin only
The box that holds this field. Define the boxes with
fieldsets.

