Skip to content

Field Types Reference

This reference documents all field types available in Trokky schemas.

All field types share these properties:

PropertyTypeDescription
namestringUnique field identifier
typestringField type
titlestringDisplay label
descriptionstringHelp text
requiredbooleanWhether field must have a value
hiddenboolean | functionHide from Studio
readOnlyboolean | functionPrevent editing
defaultanyDefault value
groupstringField group name
validationobjectValidation rules

Single-line text input.

{
name: 'title',
type: 'string',
title: 'Title',
required: true,
validation: {
min: 1,
max: 200,
},
}
OptionTypeDescription
minnumberMinimum length
maxnumberMaximum length
patternstringRegex pattern
emailbooleanValidate as email
urlbooleanValidate as URL
// Email field
{
name: 'email',
type: 'string',
validation: { email: true },
}
// URL field
{
name: 'website',
type: 'string',
validation: { url: true },
}
// Pattern validation
{
name: 'code',
type: 'string',
validation: { pattern: '^[A-Z]{3}-\\d{4}$' },
}

Multi-line text area.

{
name: 'description',
type: 'text',
title: 'Description',
rows: 4,
}
OptionTypeDefaultDescription
rowsnumber3Visible rows

Numeric input.

{
name: 'price',
type: 'number',
title: 'Price',
validation: {
min: 0,
max: 10000,
precision: 2,
},
}
OptionTypeDescription
minnumberMinimum value
maxnumberMaximum value
integerbooleanMust be integer
precisionnumberDecimal places
positivebooleanMust be positive

Toggle switch or checkbox.

{
name: 'featured',
type: 'boolean',
title: 'Featured',
default: false,
}
OptionTypeDefaultDescription
layoutstring'switch''switch' or 'checkbox'

Date picker (no time).

{
name: 'birthday',
type: 'date',
title: 'Birthday',
}

Stored Format: YYYY-MM-DD


Date and time picker.

{
name: 'publishedAt',
type: 'datetime',
title: 'Published At',
}

Stored Format: ISO 8601 (2024-01-15T10:30:00.000Z)

OptionTypeDescription
timezonestringDefault timezone

URL-friendly identifier.

{
name: 'slug',
type: 'slug',
title: 'Slug',
options: {
source: 'title',
maxLength: 96,
},
}
OptionTypeDefaultDescription
sourcestring-Field to generate from
maxLengthnumber200Maximum length
isUniquebooleanfalseCheck uniqueness

Stored Format:

{
"current": "my-blog-post",
"_type": "slug"
}

WYSIWYG editor for formatted content.

{
name: 'content',
type: 'richtext',
title: 'Content',
}
OptionTypeDescription
stylesarrayAllowed block styles
listsarrayAllowed list types
marksarrayAllowed inline marks
annotationsarrayCustom annotations
{
name: 'content',
type: 'richtext',
options: {
styles: ['normal', 'h1', 'h2', 'h3', 'blockquote'],
lists: ['bullet', 'number'],
marks: ['bold', 'italic', 'underline', 'link'],
},
}

Image or file upload.

{
name: 'featuredImage',
type: 'media',
title: 'Featured Image',
options: {
accept: ['image/*'],
maxSize: 5 * 1024 * 1024,
},
}
OptionTypeDescription
acceptstring[]Allowed MIME types
maxSizenumberMax file size in bytes
showVariantsbooleanShow variant selector
showMetadatabooleanShow metadata editor
requireAltbooleanRequire alt text

Stored Format:

{
"_type": "media",
"_ref": "media-abc123",
"alt": "Image description"
}

Link to another document.

{
name: 'author',
type: 'reference',
title: 'Author',
options: {
to: 'author',
},
}
OptionTypeDescription
tostring | string[]Target schema(s)
filterobjectFilter available documents
// Single type reference
{
name: 'author',
type: 'reference',
options: { to: 'author' },
}
// Multiple type reference
{
name: 'related',
type: 'reference',
options: { to: ['post', 'page'] },
}
// Filtered reference
{
name: 'publishedPost',
type: 'reference',
options: {
to: 'post',
filter: { status: 'published' },
},
}

Stored Format:

{
"_type": "reference",
"_ref": "author-abc123"
}

Nested structure with fields.

{
name: 'seo',
type: 'object',
title: 'SEO Settings',
fields: [
{ name: 'metaTitle', type: 'string', title: 'Meta Title' },
{ name: 'metaDescription', type: 'text', title: 'Meta Description' },
{ name: 'ogImage', type: 'media', title: 'OG Image' },
],
}
OptionTypeDescription
collapsiblebooleanCan collapse in Studio
collapsedbooleanInitially collapsed

Stored Format:

{
"seo": {
"metaTitle": "Page Title",
"metaDescription": "Description here",
"ogImage": { "_ref": "media-xyz" }
}
}

List of items.

// Array of strings
{
name: 'tags',
type: 'array',
title: 'Tags',
of: [{ type: 'string' }],
}
// Array of objects
{
name: 'links',
type: 'array',
title: 'Links',
of: [
{
type: 'object',
fields: [
{ name: 'label', type: 'string' },
{ name: 'url', type: 'string' },
],
},
],
}
// Array of references
{
name: 'relatedPosts',
type: 'array',
title: 'Related Posts',
of: [{ type: 'reference', options: { to: 'post' } }],
}
OptionTypeDescription
ofarrayItem types
sortablebooleanEnable drag-sort
layoutstring'list' or 'grid'
{
name: 'tags',
type: 'array',
of: [{ type: 'string' }],
validation: {
min: 1,
max: 10,
unique: true,
},
}

Predefined options.

{
name: 'status',
type: 'select',
title: 'Status',
options: {
list: [
{ value: 'draft', title: 'Draft' },
{ value: 'review', title: 'In Review' },
{ value: 'published', title: 'Published' },
],
},
}
OptionTypeDescription
listarrayOption items
layoutstring'dropdown' or 'radio'

{
name: 'externalUrl',
type: 'string',
hidden: ({ document }) => document.linkType !== 'external',
}
{
name: 'slug',
type: 'slug',
readOnly: ({ currentUser }) => currentUser.role !== 'admin',
}

{
name: 'title',
type: 'string',
validation: {
custom: (value, { document }) => {
if (document.status === 'published' && !value) {
return 'Title is required for published documents';
}
return true;
},
},
}

import type { Field, StringField, ReferenceField } from '@trokky/core';
const titleField: StringField = {
name: 'title',
type: 'string',
required: true,
};
const authorField: ReferenceField = {
name: 'author',
type: 'reference',
options: { to: 'author' },
};