Skip to Content
FeaturesField Types

Field Types

Fields are the building blocks of your content models. When you create a model, you add fields to define what data each record can hold.

Overview

Foir recognizes a fixed set of built-in field types. Each field type has its own editor experience, validation rules, and configuration options. The string you store in a field’s type is the lowercase name of one of these types — anything else is rejected by the platform validator.

All fields support these common options:

OptionDescription
LabelDisplay name shown in the editor
KeyUnique identifier used in APIs (auto-generated from label)
RequiredMust be filled before saving/publishing
Help TextGuidance shown below the field in the editor
Default ValuePre-filled value for new records
QueryableMaterialize the field for fast filtering/sorting (see Queryable fields)
GuardedWhich sides take the field’s own grant (see Guarded fields)

The built-in field types

There are sixteen built-in field types:

TypeStoresEditor / widget
textA string (single- or multi-line)Text input (or textarea via config.widget)
integerA whole numberNumber input
decimalAn exact decimal, carried as a stringText input (numeric keypad)
booleanTrue/falseCheckbox
dateA date or date-and-timeDate picker
selectA reference to a record of another modelRecord picker
enumA literal string token from inline optionsEnum select
jsonArbitrary JSONJSON editor
listAn ordered array of itemsArray editor
modelA model key (reference to a model schema)Model picker
referenceA reference to another recordReference picker
fileAn uploaded fileFile picker
imageAn uploaded image with metadataImage picker
videoAn uploaded video with metadataVideo picker
geopointA geographic point, { lat, lng }Map picker
proseTranslatable rich text, with models placed inlineProse editor

In addition, any model with inline mode enabled becomes usable as a field type by its own key. See Inline Schemas.

Text Fields

Text

A string field for titles, names, descriptions, and prose. By default it renders as a single-line input. To get a multi-line editor, set config.widget to textarea (see Widgets).

{ "key": "title", "type": "text", "label": "Title", "required": true }

Multi-line:

{ "key": "excerpt", "type": "text", "label": "Excerpt", "config": { "widget": "textarea" } }

Translatable: Yes, unless the field opts out.

A text field carries a value per locale without any setting. Set config.translatable to false on a field that holds a link, an anchor, a key or a slug:

{ "key": "href", "type": "text", "label": "Link URL", "config": { "translatable": false } }

The field is then left out of translation: the translation report does not list it, a translation written to it is refused, and the editor edits its one value whichever locale is on screen. Only false opts out: a field with translatable absent or set to true is translatable.

Prose

Translatable rich text — headings, bold/italic, links, lists — and, where the field admits them, your own models placed inline among the paragraphs.

{ "key": "body", "type": "prose", "label": "Body" }

That declaration is text only. A prose field admits nothing but text unless it says otherwise, which is what makes the common case the short one.

To place models in the flow, list them:

{ "key": "body", "type": "prose", "label": "Body", "config": { "allowedTypes": ["cta", "editorial_media"] } }

allowedTypes takes inline-mode model keys and the media primitives (image, video, file, reference, geopoint). Nothing outside the list can be placed, and a write carrying one is refused by key.

There is one more knob: config.passages: false turns the field into a pure arranger — models only, no typing. Use it for a section stack that should never contain loose paragraphs.

What a prose value is

A flow: { v, entries }. Each entry is either a passage (a paragraph, heading, quote or list item) or an embed (one of the models allowedTypes admits). Every entry carries an _id, minted once and never changed, so a translation or a comment anchored to a paragraph stays anchored.

Prose nests without limit. A model placed in a flow may itself have a prose field, and that flow validates in full — the modelling bounds how deep a document goes, not the format.

Reading it

A prose field resolves to a wrapper with four members:

query { page(naturalKey: "home") { body { html markdown json entries { __typename ... on Passage { _id kind token align list level spans { text marks } markDefs } ... on Cta { label href } ... on EditorialMedia { image { url alt } } } } } }
  • entries is the typed reading, and the one that keeps prose structured. Passage is a first-class member alongside your own models.
  • html and markdown are the passages only. An embed is omitted from both by declaration — the platform will not invent markup for your model, because whatever it invented would be wrong for someone. A renderer that wants the embeds reads entries.
  • json is the flow verbatim: the lossless escape hatch, where an entry nothing recognises still survives a round trip.

A fragment must select __typename explicitly. Codegen types the discriminant, but the HTTP response carries only what the document asks for — a renderer switching on __typename without it falls through every case silently.

The same read through the data client:

const page = await foir.page.findUnique({ naturalKey: 'home' }); for (const entry of page.body?.entries ?? []) { if (entry?.__typename === 'Passage') renderPassage(entry); else renderEmbed(entry); }

Inside a passage

A passage is a flat record, not a tree:

MemberWhat it carries
_idThe entry’s identity, minted once and never changed. 4 to 64 characters, starting with a lowercase letter, lowercase letters and digits only, unique within the flow
_type"passage" for text, or the placed model’s own key for an embed
kindparagraph, h1 through h6, quote, code. This is the whole set; anything else is refused
tokenA design-token override; beats kind when set
alignText alignment
list / levelList type and nesting depth, flat rather than nested. Both or neither
languageThe code language. Only valid on kind: "code"
spansRuns of { text, marks } — marks are named (bold, italic, code, …) or the _id of one of its markDefs
markDefsData for the marks that need it — links, today

These nine are the whole member set. Anything else in a passage is refused.

A soft break is a \n inside a span’s text, not a separate entry.

Writing it

The value you send is the flow itself. There is no wrapper and no partial form: send the whole { v, entries } envelope, exactly this shape and nothing else.

{ "v": 1, "entries": [ { "_id": "intro01", "_type": "passage", "kind": "paragraph", "spans": [ { "text": "Rewax twice a year, ", "marks": [] }, { "text": "see the guide", "marks": ["care01"] } ], "markDefs": [{ "_id": "care01", "type": "link", "href": "/care" }] }, { "_id": "care02", "_type": "passage", "kind": "h2", "spans": [{ "text": "Care", "marks": [] }] } ] }

v must be 1. Any other value is refused rather than guessed at, which is what lets the format change later without anyone sniffing at what is already stored.

Every entry needs a _type. It is "passage" for text. For an embed it is the placed model’s own key, and that key must be one config.allowedTypes admits.

_id is 4 to 64 characters, starts with a lowercase letter, and carries only lowercase letters and digits. No uppercase, no hyphens, no underscores. Ids are unique within a flow, and markDef ids are unique within their passage. Leave it out on a new entry and the platform mints one; once an entry has one, send it back unchanged: a translation or a comment anchored to a passage is anchored to its _id. A markDef needs its _id from the start, because the span marks that use it name it.

kind is a closed set: paragraph, h1, h2, h3, h4, h5, h6, quote, code. There is no heading.

The eight decorations are bold, italic, underline, strikethrough, code, subscript, superscript and highlight. Any other value in marks must be the _id of a markDef on the same passage, or the write is refused.

Three rules that catch people out:

  • list and level travel together. Both or neither, with level an integer from 1 to 6. Depth is this number, not a nested structure.
  • language is only valid on kind: "code".
  • Adjacent spans may not carry identical mark sets. Merge them. Without that rule the same text has unboundedly many representations and nothing can be compared.

Omit optional members rather than sending them empty. No null, and no empty markDefs.

A refusal names the _id of the entry it objects to, so a long document tells you where to look rather than only that something is wrong.

Translatable: Yes, unless the field opts out. A prose field takes config: { "translatable": false } as a text field does, and is then left out of translation. Variants apply per entry as well as per field. See Variants.

richtext and flexible

Both are retired into prose. The schema builder no longer offers either, and existing values were converted in place. A model declaring either, as a field’s type or as a list’s item type, is refused with a message telling you to use prose.

Widgets

Each field type has a default editor widget and, for some types, a small set of allowed alternatives. Override the widget with config.widget. The most common case is rendering a text field as a multi-line textarea:

{ "key": "summary", "type": "text", "config": { "widget": "textarea" } }

text also allows color, select and radio widgets, and date allows datetime-picker.

Media Fields

Image

Upload and manage images with built-in metadata support. Resolves to an object with url, width, height, alt, blurhash, dominantColor, mimeType, fileSize, focalPoint, crop, variants, webp and avif.

alt is null on a record’s image today. The alt text set on a file reaches the file library and the files query, not a record that uses the image. To publish alt text with an image, add a text field beside the image field (translatable, like any text) and read the two together.

The GraphQL type is called Image, not ImageValue. A ... on ImageValue fragment is a validation error, not an empty result.

Two things it does not do:

  • It carries no id. The file id written into the field cannot be read back through the image value — if you need the id, keep it yourself at write time.
  • include cannot reach it. include addresses relations, and an image is a value on the record rather than a related record, so it is expanded whole on every read that selects the field. omit is the lever for a read that does not render it.
{ "key": "featuredImage", "type": "image", "label": "Featured Image" }

Features:

  • Alt text — Text for accessibility
  • Focal point — Set the important area for smart cropping
  • Crops — Per-usage crop geometry
  • Blurhash — Automatically generated placeholder hash
  • Variants: pre-tokenised size presets (thumbnail, small, medium, large, xlarge, _2xl, _3xl, _4xl), with the same set in WebP and AVIF under webp and avif

Translatable: No. Put translated alt text in a text field beside the image.

Video

Upload videos with automatic processing. Resolves to a Video object (not VideoValue) with url, thumbnailUrl, previewUrl, hlsManifestUrl, width, height, duration, blurhash, dominantColor, mimeType, and fileSize.

{ "key": "heroVideo", "type": "video", "label": "Hero Video" }

Features:

  • Poster image — Thumbnail shown before playback
  • HLS streaming — Automatic manifest generation
  • Duration — Automatically detected on upload

Translatable: No

File

Any file type — PDFs, documents, spreadsheets, downloads. Resolves to a FileValue object with url, filename, mimeType, and size.

{ "key": "attachment", "type": "file", "label": "Attachment" }

Translatable: No

Numeric, Date, and Boolean Fields

There is no number. A number that counts money and a number that counts items are not the same type, and the platform will not guess which you meant.

Integer

Whole numbers: counts, quantities, seats, display order, years.

{ "key": "quantity", "type": "integer", "label": "Quantity", "required": true }

An integer travels as a JSON number. Values beyond ±2^53 are refused rather than truncated — past that point a double cannot tell one integer from its neighbour, and a value that large is an identifier rather than a quantity. Store it as text, which is what Twitter’s id_str and Stripe’s string ids do.

Translatable: No

Decimal

Exact fractional values: money, rates, percentages, weights, measurements.

{ "key": "price", "type": "decimal", "label": "Price", "required": true }

A decimal is a string on the wire, and that is the point. Record data crosses the API as JSON, whose only numeric representation is an IEEE-754 double, and base 2 cannot represent 0.1: the nearest double is 0.1000000000000000055511151231257827021181583404541015625. That is not an imprecise version of the value, it is an exact representation of a different one. A thousand line items at 0.10 sum to 99.9999999999986, and (0.1 + 0.2) + 0.3 and 0.1 + (0.2 + 0.3) disagree by a penny.

Sending a JSON number to a decimal field is refused rather than converted, because by the time it arrives the digits the author typed are already gone.

The string is the wire format, not what you hold in code. @foir/sdk/data returns a FoirDecimal with exact arithmetic — add, sub, mul, toFixed, cmp — and foir types generates that type, so a + b on two prices is a compile error rather than the string concatenation "19.99" + "2.00" would otherwise give you.

The data client makes that conversion for every decimal field of every record a call returns, inside composites, block members and included relations too, because the module foir types writes says which fields are decimals. A value it does not hand you, such as one you parse from a raw GraphQL response or read back from a cache that stored JSON, is still the string: pass it to decimal().

Scale is preserved: 19.90 stays 19.90 and is not reduced to 19.9. What the author typed is what the field serves. Comparison is numeric everywhere in the platform, so the two still match each other in a filter.

Translatable: No

Date

Date picker for publish dates, event dates, deadlines, and scheduling. Use the datetime-picker widget for date-and-time.

{ "key": "publishDate", "type": "date", "label": "Publish Date" }

Translatable: No

Boolean

Yes/no toggle for featured flags, visibility settings, and switches.

{ "key": "isFeatured", "type": "boolean", "label": "Featured" }

Translatable: No

Selection Fields

Select (record-backed)

Choose a value from the records of another model. select resolves through the dataloader to the referenced record — it is not an inline list of options. Configure it with optionModelKey (the model whose records are the choices) and, optionally, multiple for multi-select.

{ "key": "language", "type": "select", "label": "Language", "config": { "optionModelKey": "language", "multiple": false } }

Set multiple: true to allow multiple selections (stored as an array).

Translatable: No

Enum (inline options)

Choose from a fixed, inline list of { label, value } options. Unlike select, enum values are literal string tokens stored directly on the record, and there is no related model. The storefront receives a typed string-literal union of the values exactly as declared: a value is the GraphQL enum value the data API speaks, so it must be a valid GraphQL name (see defineEnumField).

{ "key": "category", "type": "enum", "label": "Category", "config": { "options": [ { "label": "News", "value": "news" }, { "label": "Tutorial", "value": "tutorial" }, { "label": "Case Study", "value": "caseStudy" } ], "multiple": false, "default": "news" } }

Set multiple: true for a multi-select that stores an array of tokens.

Translatable: No

Reference and Model Fields

Reference

Link to another record. Use for authors, related posts, parent pages, and any content relationship.

{ "key": "author", "type": "reference", "label": "Author", "config": { "referenceTypes": ["team-member"] } }

Config options: referenceTypes (array of model keys the field can link to)

Translatable: No

Model

Store a reference to a model schema (the model’s key), rather than a record. Useful for configuration that needs to point at a model type.

{ "key": "targetModel", "type": "model", "label": "Target Model" }

Translatable: No

Structured Data Fields

JSON

Arbitrary JSON data for complex or unstructured values.

{ "key": "metadata", "type": "json", "label": "Metadata" }

Translatable: No

List

Array of items for ordered collections.

{ "key": "bulletPoints", "type": "list", "label": "Bullet Points" }

Translatable: No

Queryable fields

By default, only the always-available direct columns (id, naturalKey, createdAt, etc.) and a small set of indexed fields are fast to filter and sort on. To filter or sort on a declared field, set queryable: true. The platform materializes the field into its index and rebuilds the index over existing records when the change is published. Until then, filters keep serving the fields the published model makes queryable.

{ "key": "status", "type": "enum", "label": "Status", "queryable": true, "config": { "options": [ ... ] } }

Flip queryable on text, integer, decimal, date, and boolean fields that show up in frequent filters or sorts. See Records → Filtering.

Guarded fields

A field follows its model unless a side of it is guarded. A guarded side is read, or written, only by a holder of the grant that names the field, records:read:<model>.<field> or records:write:<model>.<field>, at a reach that covers the record. A grant on the model doesn’t reach it. The platform enforces the write side on every record write path. See Guarded fields for who to give the grants to.

{ "key": "internalNotes", "type": "text", "label": "Internal Notes", "guarded": { "read": true, "write": true } }

Translatable Fields Summary

Text and prose fields carry per-locale translations. They are translatable without any setting, and a single field opts out with config.translatable: false:

Field TypeTranslatable
TextYes, unless the field sets config.translatable: false
IntegerNo
DecimalNo
BooleanNo
DateNo
SelectNo
EnumNo
JSONNo
ListNo
ModelNo
ReferenceNo
FileNo
ImageNo
VideoNo
GeopointNo
ProseYes, unless the field sets config.translatable: false. Variant overrides apply per record, per field and per entry

See Localization for details on how translations work.

In the console

Adding fields to a model

  1. Go to Models
  2. Select or create a model
  3. Click Add Field
  4. Choose the field type
  5. Configure options (label, required, help text, widget, type-specific settings)
  6. Save the model

Custom field types

You can create your own composite field types by defining a model with inline mode enabled. For example, create a “Button” model with text, URL, and style fields, then use it as a field type on any model.

See Inline Schemas for details.

Best Practices

  • Mark fields as required only when truly necessary. Optional fields give content teams more flexibility.
  • Use help text to guide editors on format expectations, character limits, or content guidelines.
  • Choose the most specific field type for the data. Use decimal for prices (not text, and not integer — the first thing to cost £4.99 has no way back), integer for counts, date for dates, and boolean for toggles.
  • Use enum for a fixed small set of tokens; use select when the choices are themselves records you manage in another model.
  • Set queryable: true on any field you need to filter or sort by on the API.
  • Translations need no enabling: every text and prose field is translatable. Set config.translatable: false on the ones that hold a link, an anchor, a key or a slug, so a translator is never offered them.
  • Use references instead of duplicating content. Link to a shared “Author” record rather than entering the author name on every post.
Last updated on