Column types

Every column type the CMS understands and the editor it gets.

On this page

The CMS picks a field's editor from the column's type, from metadata registered in _collection_fields, and in a few cases from the values already in the column. This page lists what you get for each.

A site database has three column types, text, integer and real, so the metadata the AI registers decides most of its editors, as The three column types shows.

How the editor is chosen

The checks run in order, and the first match wins:

  1. A multi reference field registered in _collection_fields.
  2. A real foreign key column.
  3. An explicit ui_type of color, richtext, file, code, json, boolean, date, datetime, image or imagearray. A ui_type of array marks a list, which then gets the list editor in the next step.
  4. The column's type.
  5. For plain text columns with no metadata, the shape of the values already stored.

The editor is picked from what the row held when you opened it, so a field never swaps to a different editor while you type in it.

The three column types

text gets the string editors, and integer and real get the number input. Booleans, dates, JSON and lists are stored in these three types too, so the AI registers what such a column holds in _collection_fields when it creates it:

ui_type Column type Editor
boolean integer holding 1 or 0 Dropdown of true and false
date text holding a calendar date Date picker
datetime text holding an ISO 8601 UTC timestamp Date and time picker
json text holding a JSON object JSON editor with a row per key and Add field, or the raw JSON under Edit as JSON, validated as you type
array text holding a JSON array Chip input, one value at a time
imagearray text holding a JSON array Gallery upload, an ordered list of images each with its own alt text

The five in Metadata driven fields, color, richtext, code, file and image, are registered the same way. A gallery is imagearray, and its <column>_alt companion is registered as array. Without this metadata a boolean column shows a number input, and a date, JSON or list column a plain text box.

Metadata driven fields

These five are declared by the AI in _collection_fields at the same time the column is created. The column type stays text, and only the metadata decides the widget.

ui_type Column type Editor
color text Color swatch with a native color picker, validated as a hex color
richtext text WYSIWYG editor: bold, italic, underline, strikethrough, paragraph and headings 1 to 6, quote, bullet and numbered lists, links, inline images, code blocks, tables and embeds. Horizontal rules, subscript and superscript already in the text are kept. See Rich text fields
code text Code editor with HTML, CSS and JavaScript highlighting and a Preview tab. Stores the code exactly as written, and your site runs it. See Code fields
file text File upload with drag and drop, showing the file name with download, replace and remove actions. Stores the uploaded file's URL
image text Image upload with a preview, replace and remove actions, and an alt text popover that takes up to 300 characters

A gallery is imagearray instead, as The three column types explains.

The rich text editor keeps code from other services in embeds, blocks your site runs exactly as written. When a richtext value holds code outside an embed, such as an iframe or a script written straight into its HTML, the editor turns the paragraph or block around it into an embed, so editing the text keeps it.

An image column always comes with a companion column named <column>_alt of the same type. The CMS hides that companion and edits it from inside the image widget.

Without the metadata, a text column holding a file URL is indistinguishable from any other string, so it renders as a plain text box. That is why the AI registers it up front. An empty code field without its metadata gets a plain text box too.

Detected without metadata

Three things are inferred from the values already in a column, so they can appear on a column nobody registered:

  • Code. A value that starts with a tag and contains a <script>, <style>, <iframe>, <noscript>, <link>, <meta>, <template> or <source> tag, an embedded object, video, audio or canvas, a form control, a whole HTML document, an inline event handler such as onclick, or an <svg> inside other markup opens in the code editor, as long as it passes the code checks under Validation. Code kept inside the embeds of a rich text value does not count. Text that only mentions a tag, such as Wrap your CSS in a <style> block., keeps its usual editor, and an SVG file stays an image.
  • Rich text. A value containing other HTML markup opens in the rich text editor rather than a text box.
  • Images. A text column whose values look like image URLs is treated as an image field, and a list column whose entries do is treated as a gallery. This needs at least one non empty value to go on, which is why a freshly created image column still needs its image metadata.

A hex color value in a plain text column also switches that field to the color picker.

Long versus short text is inferred too. A value with a line break always gets a textarea, so no line is lost. Otherwise, column names like description, content, body, bio, summary and notes get a textarea, and names like name, title, slug, email, url, status and code get a single line input. Failing both, a value longer than 150 characters gets the textarea.

Relationship fields

Kind How it is stored Editor
Single reference An ordinary foreign key column, for example author_id text REFERENCES authors(id) Searchable single select of rows in the target collection, loading twenty at a time
Multi reference A join table plus a multi_reference row in _collection_fields Multi select with checkboxes and removable chips, searchable, paged twenty at a time

Single references are read straight from the database's own foreign key catalog, so they need no metadata. The field label drops a trailing _id, so author_id reads "Author".

Multi reference join tables are hidden from the Collections sidebar. Turn on Show system collections in the CMS Settings sub-tab to see them.

System columns

Column Behaviour
The primary key, usually id Never editable. Left out while creating, shown read only when editing
created_at, created_on, inserted_at, inserted_on Never editable, and left out of the editor
updated_at, updated_on, modified_at, modified_on Never editable, and left out of the editor. Re-stamped by a database trigger on every edit
slug Slug input with a live preview of the row's public URL, click to copy. Auto filled from title or name while creating, or while editing an item whose slug is empty, until you edit it. Kept to 80 characters

Validation

The editor blocks a save and shows the reason under the field. Apart from Required, it only checks the fields you changed, so an older value that would not pass today does not stop you saving the rest of the item.

Case Message
A NOT NULL column left empty Required
Malformed JSON Invalid JSON
A non numeric value in an integer or real column Must be a number
A decimal in an integer column Must be a whole number (no decimals)
A whole number too large or too small for an integer column Out of range for integer (-9223372036854775808 to 9223372036854775807)
A color field that is not a 3, 4, 6 or 8 digit hex color Must be a hex color, e.g. #1a2b3c
A code field with a <script>, <style>, <iframe>, <textarea>, <title>, <noscript>, <noembed>, <noframes> or <xmp> tag that is never closed, outside an <svg> or <math> element Close the <script> tag with </script>, naming the tag
A code field with an HTML comment that is never closed Close the HTML comment with -->
A code field with a CDATA section inside an <svg> or <math> element that is never closed Close the CDATA section with ]]>
A code field with a tag cut off before its > Finish the <div> tag with >, naming the tag
A code field with a <! or <? tag, such as a doctype, cut off before its > Finish the <! tag with >, or the same with <?
A code field containing <plaintext> Remove the <plaintext> tag, it hides everything after it
A code field containing <base> Remove the <base> tag, it changes where every link on your page points
A code field longer than 100,000 characters Must be 100,000 characters or fewer

An embed in a rich text field gets the same code checks, with the message under its code editor, before Insert embed or Save embed can add it.

Next