Fields

Group

Fields nested under one key, shown as one section in the admin.
The group field in the admin

Example

cms/collections/venues.ts
export const venues = defineCollection({
  fields: {
    name: { type: "text", required: true },
    address: {
      type: "group",
      fields: {
        street: { type: "text" },
        zip: { type: "text", width: "1/3" },
        city: { type: "text", required: true, width: "2/3" },
      },
    },
  },
});

A read returns an object:

venue.address; // { street, zip, city } | null | undefined
venue.address?.city;

Render it

{venue.address && (
  <address>
    {venue.address.street}<br />
    {venue.address.zip} {venue.address.city}
  </address>
)}
  • An optional group can be missing, so read it with ?..
  • A required field inside applies only when the group is there. Make the group required to demand it.
  • Groups can hold groups, lists and every other field type.

Tabs and boxes inside

A group can have its own tabs and fieldsets, like a collection. appearance: "plain" drops the box and heading, which fits a group that already sits in its own tab:

fields: {
  seo: {
    type: "group",
    tab: "seo",
    appearance: "plain",
    fields: {
      title: { type: "text" },
      description: { type: "textarea", rows: 3 },
    },
  },
}

Limits

  • Filters accept only top-level fields, not fields inside a group.
  • unique does not work inside a group.
  • private and access on a group apply to the whole group.
  • In a localized collection, a group is localized as a whole. Its fields MUST NOT set localized.

Options

The nested fields.A tab bar for the fields inside. A field picks its tab with tab.Boxes around fields inside. A field picks its box with fieldset.Show the fields without the box and heading.