Reference
Fields
Every field builder of @micacms/core, its options, and what it stores in the repository.
7 min readImport the builders from @micacms/core. Each builder gives plain data, so the editor can read the model from .mica/schema.json.
Options of every field
| Option | Effect |
|---|---|
label | The label in the editor. Default: the key, as words. |
description | Help text below the field. |
required | An empty value cannot be published. Editors can save it before that. |
listed | Shows the value as a column in the list of a collection. |
readonly | The editor shows the value, but cannot change it. |
hidden | Mica keeps the value, but the editor does not show it. |
group | Fields with the same group show in one box. |
width | "full", "half" or "third" of the form row. |
localized | A value for each locale of the site, stored as { "de": …, "en": … }. required and default apply to the default locale. { fallback: false } keeps a missing value empty on the website. Not for object(), repeater() and the ID of a collection. See Localization. |
The build stops on an option that is not in these tables, for example a typo. A field with an option from a newer @micacms/astro is read-only in an older Mica until you upgrade it.
The builders
| Builder | Stores | Options |
|---|---|---|
text() | A string. | minLength, maxLength, placeholder, default, pattern (a regular expression; it must match the whole value, with the u flag; a group that repeats cannot contain a repeat, so (a+)+ is refused, but (-[0-9]+)? is allowed), patternMessage. |
textarea() | A string with line breaks. | minLength, maxLength, rows, placeholder, default. |
richText() | Markdoc, in a <key>.mdoc file beside the entry. | toolbar: "minimal" (bold, italic, link), "default" (also headings and lists), "full" (also strike, blockquote, horizontalRule, table, image), or a list of these features. Also maxLength, default. |
number() | A number. | min, max, step, integer, unit (shown in the field, for example "m²"), default. |
boolean() | true or false, never empty. | default. |
date() | "2026-10-13", or with includeTime a date and time with its offset. | includeTime, min, max, default. |
email() | An email address. | placeholder, default. |
url() | A web address. | placeholder, default. |
id() | Lower-case letters, digits and hyphens. | from: the key of the field that gives the ID while the editor types. maxLength. |
select({ options }) | The value of the choice, or a list with multiple. | options: a list of { label, value }. multiple, default. |
object({ fields }) | An object with the given fields. | fields, collapsible, collapsed. |
repeater({ fields }) | A list of objects. | fields, min, max, itemLabel (the key of the field that names a row: a text, or a single relation, which shows the title of its entry), addLabel. |
relation({ collection }) | The ID of an entry, or a list with multiple. For a reference set, the id of an item. | collection: a collection of the model, or a reference set. multiple. |
media() | The path of a file, or { path, alt } with alt. A list with multiple. | accept: "image" (JPEG, PNG, GIF, WebP, AVIF), "document" (PDF), "any" (every type that Mica knows), or a list of image, pdf, gpx, kml, geojson, zip and csv. multiple, max, alt: "required" or "optional". |
color() | A hex colour, for example "#0f766e". | presets: colours to choose from. default. |
coordinates() | { lat, lng }. With a map also zoom, from 0 to 22. | map: "liberty", "bright" or "positron" (OpenFreeMap), or { style, hosts } for a style of your own, with https only. The editor's browser loads the tiles from that host. |
tags() | A list of short words, never null: no tags is []. | max, maxLength, suggestions, default. |
Defaults and empty values
A default fills the field of a new entry, and of a singleton that has no file yet. It never fills a value that is missing in a stored entry: such a value is empty, null, false or [], and your templates must handle it. So a changed default does not change the stored entries, and a cleared field stays cleared.
Values that the model does not have
A save keeps a key in index.json and a .mdoc file that the model does not declare, for example content for a field that a newer model adds. Your templates do not get them, and npx mica check warns about them. To delete them, see Change the model. A key in a list row without _key is not kept, because such a row has no identity when the order changes.
The ID of a collection
The first id() among the fields of a collection is the entry's ID. It is also the name of the entry's folder, so it is never empty, and it cannot be localized. A second id() among the same fields stops the build. An id() in an object or in a singleton, or a localized id(), is an ordinary value, for example one page name for each language. A localized id() among the fields of a collection must be unique in each locale: npx mica check and Publish report a value that another entry has.
Where an entry is stored
Each entry is a folder <id>/ with index.json, the .mdoc files and the entry's media, and each singleton is a folder <name>/ with the same files. See Content model.
Each rich-text field has its own .mdoc file, named by the field's path: body.mdoc, seo.intro.mdoc, and body.de.mdoc for a localized field. In a repeater(), each row with rich text has a key, _key, in index.json, and the file names the row by its key: sections.k3f9a2.body.mdoc. Then a new order of the rows changes only index.json. Mica writes the key; do not change it. Your templates do not get it.
Collections and singletons
import { collection, defineSite, singleton, id, text } from "@micacms/core";
export const site = defineSite({
root: "./content",
collections: {
news: collection({ label: "News", url: "/news/{id}", fields: { title: text({ required: true }), id: id({ from: "title" }) } }),
},
singletons: {
settings: singleton({ label: "Website", fields: { tagline: text() } }),
},
});
Option of collection() | Effect |
|---|---|
label, labelSingular | The names in the editor, for example "News" and "Article". |
description | Text below the title of the list. |
fields | The fields. |
titleField | The key that names an entry in lists. Default: title, else the first text(), else the ID. |
idField | The key of the ID. Default: the first id(). |
defaultSort | { field, direction } for the list in the editor. field is a field of the collection or "position". Text sorts alphabetically in English, and a date with a time by its instant. _mica.position on the website follows it too: sort your pages with inEditorOrder from @micacms/astro. |
sortable | Editors can put the entries in an order. Mica keeps it in _order.json. |
url | The page of an entry on the website, with {id} once, such as /news/{id}. It can also name other fields of the collection with one value, each as a whole part of the path between two /: a select() or relation() without multiple, or a date() without a time, such as /{activity}/{id}. A relation gives the ID of its entry. The address has the saved value, percent-encoded. While one of the fields is empty, the entry has no page. On a site with locales, it can name {locale} once, as a whole part of the path, such as /{locale}/news/{id}: the editor then shows the page of the form's language. With MICA_SITE_URL, an entry shows "Open on website". See Preview changes. |
singleton() takes label, description, fields and url (its page, such as /about or /{locale}/about, without {id}). defineSite() takes root, label, collections, singletons and references, and for a multilingual site locales, defaultLocale (default: the first locale), fallback and prefixDefaultLocale (default: false, as in Astro: the default locale's address has no prefix). See Localization.
Reference sets
referenceSet({ label, file, id, title }) declares data of the website that Mica never edits, and that a relation() can point to. It goes in references of defineSite(), under the name of the website's own Astro collection for that file. file is the file from the project root, id the key of an item's id (default id), and title the key that the editor shows. See Reference data.