5.8 KiB
| title | aliases | tags | sources | created | updated | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Text Field |
|
|
|
2026-05-15 | 2026-05-15 |
Overview
The Text Field is one of the most-used Payload fields. It saves a plain string to the database and renders a simple text input in the Admin Panel. Set type: 'text' in the field config.
import type { Field } from 'payload'
export const MyTextField: Field = {
name: 'pageTitle',
type: 'text',
required: true,
}
Key Takeaways
- Stores a
stringin the database; one column per field (or multiple rows whenhasMany: true). hasMany: trueturns it into an ordered string array — useminRows/maxRowsto bound it.unique: truecreates a database-level unique index — not just an app-level check.saveToJWT: trueembeds the value in the user JWT — useful for roles/flags without extra DB lookups. See wiki/payloadcms/authentication-token-data.hidden: trueexcludes the field from all APIs and the Admin Panel but still persists to DB.virtual: true(boolean) disables DB persistence; or pass a string path to link to a wiki/payloadcms/fields-relationship.- Supports
localized: true— requires wiki/payloadcms/localization in root config. - Built-in Slug Field (
slugField()) is available frompayload— auto-generates URL-safe slugs from another field, with lock/unlock UI and re-generate button.
Config Options
| Option | Description |
|---|---|
name * |
DB property name |
label |
Admin Panel label (string or { [lang]: string }) |
unique |
DB-level unique index |
minLength / maxLength |
Character length validation |
validate |
Custom validation function (runs client + server) |
index |
Build a DB index for faster queries |
saveToJWT |
Include in user JWT (top-level auth fields only) |
hooks |
Field lifecycle hooks |
access |
Field-level access control |
hidden |
Remove from all APIs; still saved to DB |
defaultValue |
Default value or function |
localized |
Per-locale string values |
required |
Non-empty validation |
hasMany |
Store as ordered string array |
minRows / maxRows |
Array bounds when hasMany: true |
virtual |
Disable DB column (boolean) or link to relationship (path string) |
typescriptSchema |
Override generated TS type with JSON schema |
Admin Options
Extends the base wiki/payloadcms/fields-overview with:
| Option | Description |
|---|---|
placeholder |
Placeholder string in the text input |
autoComplete |
Browser autocomplete attribute value |
rtl |
Force right-to-left text direction (true) |
hasMany Mode
{
name: 'tags',
type: 'text',
hasMany: true,
minRows: 1,
maxRows: 10,
}
Stores an ordered array of strings. Each value is a separate DB entry; the order is preserved.
Built-in Slug Field
Import slugField from payload to get an auto-generating slug with lock UI:
import { slugField } from 'payload'
export const PagesCollection: CollectionConfig = {
slug: 'pages',
fields: [
{ name: 'title', type: 'text' },
slugField(), // defaults: name='slug', useAsSlug='title'
],
}
Slug Config Options
| Option | Default | Description |
|---|---|---|
name |
'slug' |
Field name |
useAsSlug |
'title' |
Source field to generate slug from |
checkboxName |
'generateSlug' |
Lock/unlock checkbox field name |
disableUnique |
false |
Disable unique index (useful for multi-tenant slugs) |
localized |
false |
Localize both slug and checkbox fields |
required |
true |
Require the slug field |
overrides |
— | Function to modify default field definitions |
slugify |
— | Override default slugify function |
position |
— | Admin Panel position |
Custom Slugify Function
import slugify from 'slugify'
slugField({
slugify: ({ valueToSlugify, data, req }) =>
slugify(valueToSlugify, { lower: true, strict: true }),
})
Warning: The built-in Slug Field is experimental and may change or be removed in future releases.
Custom Components
Payload supports custom Server and Client Components for both the Field and Label slots. Import base components from @payloadcms/ui and wrap them.
// Server Field component
import { TextField } from '@payloadcms/ui'
import type { TextFieldServerComponent } from 'payload'
export const CustomTextField: TextFieldServerComponent = ({
clientField, path, schemaPath, permissions,
}) => (
<TextField field={clientField} path={path} schemaPath={schemaPath} permissions={permissions} />
)
See wiki/payloadcms/custom-components-authoring for RSC vs Client rules and Import Map details.
Related Articles
- wiki/payloadcms/fields-overview — shared config: virtual, validation, defaultValue, admin options
- wiki/payloadcms/fields-email — text variant with built-in format validation
- wiki/payloadcms/fields-number — numeric equivalent with
hasManysupport - wiki/payloadcms/fields-select — enum dropdown (use when values are constrained)
- wiki/payloadcms/database-indexes —
uniqueandindexgotchas - wiki/payloadcms/authentication-token-data —
saveToJWTpattern - wiki/payloadcms/localization — enabling
localizedfields - wiki/payloadcms/custom-components-authoring
Source: raw/fields__text.md — https://payloadcms.com/docs/fields/text