Field Groups
Define reusable field groups that can be shared across collections and singles.
Field groups are reusable field structures. Define a set of fields once as a field group, then embed it in any number of collections or singles. Each usage creates a separate data instance — field groups are schemas, not shared documents.
Source of truth: the
FieldGroupConfiginterface lives inpackages/nextly/src/field-groups/config/types.ts. ThedefineFieldGroup()helper is inpackages/nextly/src/field-groups/config/define-field-group.ts.
Key characteristics:
- Templates, not documents. Field groups define a field structure; each embed creates its own data row.
- Own database table. Each field group gets a table derived from its slug and prefixed with
comp_(e.g.comp_seo). The name is always derived; it cannot be overridden. - Nesting. A field group's fields can include
componentfields referencing other field groups, to any depth. A field group cannot be placed inside itself, directly or through other field groups. - Slug uniqueness. Field group slugs must be unique across field groups, collections, and singles.
- Dual creation. Define in code with
defineFieldGroup()or visually in the Visual Schema Builder.
Use defineFieldGroup() from nextly to create field groups in TypeScript:
import {
defineFieldGroup,
text,
textarea,
upload,
} from "nextly";
export default defineFieldGroup({
slug: "seo",
label: { singular: "SEO Metadata" },
admin: {
category: "Shared",
icon: "Search",
description: "Search engine optimization metadata",
},
fields: [
text({ name: "metaTitle", required: true, label: "Meta Title" }),
textarea({
name: "metaDescription",
label: "Meta Description",
maxLength: 160,
}),
upload({ name: "ogImage", relationTo: "media", label: "OG Image" }),
text({ name: "canonicalUrl", label: "Canonical URL" }),
],
});Field groups can also be created visually in the admin UI:
- Navigate to Field Groups in the sidebar.
- Click Create Field Group.
- Name it and add fields using the drag-and-drop Schema Builder.
- Save — the field group is immediately available for use.
Builder-created field groups work identically to code-defined ones; both produce the same database schema and API behavior.
Field group options
Only slug and fields are required.
| Option | Type | Required | Description |
|---|---|---|---|
slug | string | Yes | Unique identifier across field groups, collections, and singles. Used as the DB table prefix (comp_{slug}). Follows the address rule. |
fields | FieldConfig[] | Yes | Array of field definitions. |
label | { singular: string } | No | Display name in the admin UI. Auto-generated from slug if omitted (e.g. social-link → Social Link). |
admin.category | string | No | Category that groups field groups in the sidebar and selector modal (e.g. "Shared", "Blocks"). |
admin.icon | string | No | Lucide icon name shown in sidebar and field group selector. |
admin.description | string | No | Help text in the field group selector modal. |
admin.hidden | boolean | No | Hide from admin navigation. Still usable in code and via API. |
admin.imageURL | string | No | Preview image URL shown in the field group selector. |
description | string | No | General description; falls back to admin.description. |
custom | Record<string, unknown> | No | Arbitrary metadata for plugins or custom code. Not persisted. |
Field groups do not have hooks or access control of their own. They inherit hook execution and access checks from the collection or single they're embedded in.
Using field groups in collections and singles
Once defined, embed a field group in any collection or single using the fieldGroup() field helper. There are three usage modes.
Single field group (fixed type)
Embed exactly one instance of a specific field group:
import { defineCollection, fieldGroup, text, richText } from "nextly";
export default defineCollection({
slug: "pages",
fields: [
text({ name: "title", required: true }),
richText({ name: "content" }),
fieldGroup({ name: "seo", component: "seo" }),
],
});Dynamic zone (multiple field group types)
Let editors choose from several field group types, which suits flexible page builders:
import { defineCollection, fieldGroup, text } from "nextly";
export default defineCollection({
slug: "pages",
fields: [
text({ name: "title", required: true }),
fieldGroup({
name: "layout",
components: ["hero", "cta", "content-block", "image-gallery"],
repeatable: true,
}),
],
});Repeatable single field group
An array of the same field group, for example a list of feature cards:
import { defineCollection, fieldGroup, text } from "nextly";
export default defineCollection({
slug: "landing-pages",
fields: [
text({ name: "title", required: true }),
fieldGroup({
name: "features",
component: "feature-card",
repeatable: true,
minRows: 1,
maxRows: 12,
}),
],
});The component field's full option reference lives in Fields → Component.
Example: hero section field group
import {
defineFieldGroup,
text,
upload,
select,
option,
} from "nextly";
export default defineFieldGroup({
slug: "hero",
label: { singular: "Hero Section" },
admin: {
category: "Blocks",
icon: "Image",
description: "Full-width hero banner with heading and CTA",
},
fields: [
text({ name: "heading", required: true, label: "Heading" }),
text({ name: "subheading", label: "Subheading" }),
upload({
name: "backgroundImage",
relationTo: "media",
label: "Background Image",
}),
text({ name: "ctaText", label: "CTA Button Text" }),
text({ name: "ctaLink", label: "CTA Button Link" }),
select({
name: "alignment",
label: "Content Alignment",
options: [option("Left"), option("Center"), option("Right")],
defaultValue: "center",
}),
],
});Groups with no name
A group with no name only lays a field group's form out. The data fields inside it are stored on the instance's own row, as columns of the field group's table, exactly as the fields beside the group are. A field group placed inside such a group keeps its instances in its own table, as one placed beside it does.
Field groups made with an earlier Nextly release stored nothing for a data field inside a group with no name, and their tables have no column for it. The next save of the field group in the Visual Schema Builder, or the next nextly migrate:create, writes a migration that adds each missing column as a nullable column, and changes no column that already exists. When the table was made before Builder saves wrote migrations, the save's review lists each added column for you to confirm. Until that migration is applied, the field group is read and written as before, and the values of those fields are not stored. Reconcile keeps those fields in the definition and lists each column still to be added.
Field group nesting
Field groups can embed other field groups using the component field type, at any depth. There is no depth limit.
Each level's values are stored, read and migrated like the outer field group's. A field group placed directly in another's fields is stored as rows of its own table, each pointing at the row of the instance that holds it; one placed inside a group or repeater is stored in that container's value. Either way it is validated by its own fields' rules, a required one is required, and removing an instance removes everything placed in it. Filtering reaches a field group's own fields only (hero.title); a path that goes further (hero.cta.label) is refused as a field that cannot be filtered on.
A field group placed inside itself, directly or through other field groups (a holds b, which holds a), is a cycle, and a cycle is refused where it is written. A placement inside a group, a repeater or a list of allowed field groups counts as well. The refusal names the field groups in the cycle:
defineConfig()refuses a cycle among the field groups your code defines.- Your app refuses to start when a cycle takes in a field group your code defines, including one closed by a field group made in the Schema Builder.
- The Schema Builder refuses a save that would leave the saved field group in a cycle.
A cycle among Schema Builder field groups saved before cycles were refused does not stop your app from starting. The start, and CLI commands that load your configuration such as nextly migrate:check, name it in a warning. The next save of any field group in it is refused until one of them stops placing the next.
import { defineFieldGroup, text, fieldGroup } from "nextly";
export default defineFieldGroup({
slug: "faq-item",
label: { singular: "FAQ Item" },
fields: [
text({ name: "question", required: true }),
text({ name: "answer", required: true }),
fieldGroup({ name: "cta", component: "cta" }),
],
});Next steps
- Fields — all field types available inside field groups
- Collections — where field groups are most commonly used
- Singles — embed field groups in single-document content