Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Form Fields

Every built-in form field type, with the keys it reads. The keys every field takes (label, span, rules, …) are on Form Descriptor; a type of your own is Writing a Field Type. A key a type does not read is refused, naming the entry and the keys it accepts.

text

fields:
  email: { type: text, input: email, placeholder: you@acme.test }
  price: { input: number, min: 0, step: 0.01 }
  site:  { input: url, copy: true }
KeyDefaultDescription
inputtexttext, email, tel, number, url, color.
placeholdernoneThe placeholder.
counterautoauto, true, false. auto: with a max_length rule, shown once four fifths of it are used.
min, max, stepnoneA number input’s bounds and step.
copyfalseA url input: a button copying the value.

text is the type when none is written. An email input adds the email rule.

textarea

fields:
  body: { type: textarea, rows: 8, placeholder: Write here, grow: false }
KeyDefaultDescription
rowsThe height, in lines.
placeholdernoneThe placeholder.
growtrueAs tall as its text, from rows up to most of the window.
counterautoAs for text.

richeditor

fields:
  body: { type: richeditor, rows: 12, toolbar: [format, bold, italic, "|", link, image] }
KeyDefaultDescription
rowsThe height, in lines.
placeholdernoneThe placeholder.
toolbarevery entry, in this orderA list from format, bold, italic, underline, strike, bullet_list, ordered_list, link, image, table, rule, undo, redo, `

Stores HTML kept to that set; an image from the library is linked to the record.

markdown

fields:
  body: { type: markdown, rows: 12, preview: side }
  terms: { type: markdown, preview: side, preview_url: acme/terms/preview }
KeyDefaultDescription
rowsThe height, in lines.
placeholdernoneThe placeholder.
previewtabtab (or true): a Preview tab. side: the preview beside the text, rendered again as the text or any other field of the form changes. off (or false): none.
preview_urlthe built-in rendererAn endpoint of your own, under the admin (acme/terms/preview) or absolute (/render). It receives the form’s fields by POST, with text holding the editor’s content, and answers HTML, or a PDF to show the document itself.

Stores the markdown as written; the site renders it with the markdown filter.

codeeditor

fields:
  styles: { type: codeeditor, language: css, rows: 20, wrap: true }
KeyDefaultDescription
languagetexttext, html, css, javascript, json, yaml, markdown, jinja.
rowsThe height, in lines.
line_numberstrueNumbers in the gutter.
wrapfalsefalse: long lines scroll.
placeholdernoneThe placeholder.

select

fields:
  status: { type: select, options: [{ value: "", label: Any }, { value: draft, label: Draft }], search: auto }
KeyDefaultDescription
optionsA list of { value, label, disabled, group }, or the name of an option source. group is the heading the choice sits under.
searchautoauto, true, false. auto: past 10 choices, the dropdown is searched. An option with an empty value is what clearing chooses.

radio

fields:
  size: { type: radio, options: [{ value: s, label: Small }, { value: l, label: Large }] }
KeyDefaultDescription
optionsA list of { value, label, note, disabled }, or the name of an option source. note is a second line under the label.

checklist

Boxes in groups. The column holds the ticked values as a JSON array of text.

fields:
  topics:
    type: checklist
    rules: [required]        # a box must be ticked
    options:
      - { value: news, label: News }
      - group: Sport
        options:
          - { value: football, label: Football, note: Every league }
          - { value: cricket, label: Cricket }
    select_all: auto
    search: auto
    expand: auto
KeyValuesDefault
optionsA list of { value, label, note } and { group, options }, nested to any depth, or the name of an option source.None
select_allauto, true, falseauto: past 10 choices
searchauto, true, falseauto: past 20 choices
expandauto, all, noneauto: past 10 choices in more than one group, a group with every box ticked or none starts closed and a group partly ticked starts open

A value listed twice stops the boot, naming it.

taglist

Short texts typed one at a time. The column holds them as a JSON array of text.

fields:
  aliases:
    type: taglist
    placeholder: "Another name"
    rules: [required]        # at least one tag
KeyValuesDefault
placeholdertextNone

Enter or a comma adds what is typed; a pasted list splits on commas and lines. A tag typed twice is kept once. In a repeater row:

fields:
  outlets:
    type: repeater
    fields:
      name:    {}
      domains: { type: taglist }
lat.on('taglist:changed', function (detail) { console.log(detail.tags); });

switch

fields:
  is_live: { type: switch, label: Published }

No keys. A yes or no over a boolean column.

section

fields:
  delivery:  { type: section, label: Delivery, help: Where and when the order ships. }
  address:   {}
  ship_date: { type: date }

No keys. A heading over the fields after it, with help as the line beneath. Nothing is stored or submitted. A trigger shows and hides the heading:

fields:
  kind:    { type: select, options: [{ value: post }, { value: event }] }
  when:    { type: section, label: When, trigger: { action: show, field: kind, condition: "value[event]" } }
  starts:  { type: date, trigger: { action: show, field: kind, condition: "value[event]" } }

date

fields:
  published_at: { type: date }

No keys. The value must be a date.

password

fields:
  token: { type: password, reveal: false }
KeyDefaultDescription
revealtrueA button shows what was typed.

sensitive

fields:
  api_token: { type: sensitive }

A secret sealed under the application key before it is stored and shown as a mask. The eye shows the stored value and writes <entity>.reveal to the audit log (settings.reveal on a settings screen); typing replaces the value whole, and a blank or the mask submitted back leaves it as it is. The column is text; lat crypt rotate re-seals it after a key rotation.

fields:
  service_key:
    type: sensitive
    file: true
    accept: [.json, .p12]
    max_size: 16kb
KeyDefaultDescription
filefalseThe secret is an uploaded file, sealed in the same text column.
acceptanyThe extensions an upload may have.
max_size64kbThe largest upload, in bytes or as 16kb, 1mb. At most 512kb.

A sealed file shows its name, size and fingerprint, has no Reveal, and is replaced by choosing another.

use laterite_core::SealedFile;

let sealed = record.get("service_key").and_then(|v| v.to_text()).unwrap_or_default();
let key = SealedFile::open(&crypt, "service_key", &sealed)?;
let json: serde_json::Value = serde_json::from_slice(&key.bytes)?;

id

fields:
  post_id: { type: id }

No keys. A record id held as a number, as a hidden input; a relation’s foreign key is one.

reference

fields:
  author_id: { type: reference, source: acme.authors }
KeyDefaultDescription
sourceA registered picker source. Required.

The column holds the chosen id as a number.

repeater

fields:
  links:
    type: repeater
    min_items: 1
    max_items: 10
    summary_field: label
    fields:
      label: {}
      url:   { input: url }
KeyDefaultDescription
fieldsThe row’s fields, a map like the form’s. Required. A field with no label shows its name.
min_items0The fewest rows: this many show from the start, and Remove is off at this count.
max_itemsnoneThe most rows: Add, the row’s add and Duplicate are off at this count.
displayautoauto, inline, list. auto: one field a row is compact; past 3 fields a row, rows collapse to the line naming them.
summary_fieldthe first fieldWhich field names a collapsed row.
expandedfalseList rows show open.
promptAddThe Add button’s label.
reordertrueEach row moves up and down.
duplicatetrueEach row copies into a new one beneath it.

A row of one field is compact: one line a row, each with add and remove, and always at least one line.

fields:
  aliases:
    type: repeater
    max_items: 5
    fields:
      name: { placeholder: "Another name" }

media

fields:
  cover_id: { type: media, mode: image }
  gallery:  { type: media, max: 6 }
KeyDefaultDescription
modefileimage offers images alone and shows thumbnails.
max1How many files the field holds; 0 is no limit.
publicfalseThe file is shown to people who are not signed in, so a private file is refused.

The columns it writes and the links it keeps: Media Field.