Fieldia

Writing Fieldia pages: a guide for AI agents

A Fieldia page is one JSON document that describes a form, a survey or a record screen. An app stores it, and Fieldia draws it in the browser — in React, Vue, Angular or plain JavaScript. This guide is for an AI agent (or a person) who writes pages: what a page holds, how to check one before it is stored, the mistakes the checks catch, and a worked example.

What a page is

A page is data, never code: no functions, no components, no scripts. It has five parts.

{
  "fieldia": "0.13",
  "id": "contact",
  "data": { "kind": "responses" },
  "fields": {
    "name": { "type": "char", "label": "Your name", "required": true }
  },
  "layout": {
    "type": "sections",
    "id": "root",
    "children": [{ "type": "field", "id": "f-name", "field": "name" }]
  }
}

Conditions — when a part shows, locks or is required — are expressions over the values, written as Odoo writes them: "invisible": "topic != 'sales'", with ==, !=, and, or, not, and words in single quotes.

Every setting is described in the JSON Schema: @fieldia/core/page.schema.json (draft 2020-12). An editor or a model can read each setting's words there.

How to check a page

Check every page before it is stored. validatePage decides; a viewer gives its verdict in two steps:

WhereWhat to callWhat it does
Where pages are madevalidatePage(page) from @fieldia/core/schemaThe whole check: every key and value, every name a part or a condition uses, every expression. Its answer lists each problem by its path, and warnings beside it.
In CInpx fieldia-check pages/ from @fieldia/testingvalidatePage over every .json file, one line per problem; --strict fails on warnings too.
In the browser, before the drawcheckPage(page), as every viewer runs itWhat 0.35's viewer refused: the outline, every name a part or a condition uses, every expression. A page it refuses is never drawn: the form's place says "This form cannot be shown", with what is wrong under it.
In the browser, after the drawawait checkPageWhole(page), as every viewer runs it once the page is drawnThe same verdict as validatePage, without the validation library, fetched as a part of its own. In 0.36 what only it finds is drawn and said, once in the console and to the app's onError; from 0.37 it is refused (page.invalid).
Before storingstampPage(page)The page stamped with the lowest format its settings need, so a viewer of an older Fieldia reads it.
import { stampPage, validatePage } from '@fieldia/core/schema';

const checked = validatePage(page);
if (!checked.ok) for (const issue of checked.issues) console.log(`${issue.path}: ${issue.message}`);
else await store.put(page.id, stampPage(checked.page));

The JSON Schema checks the shape alone. validatePage also checks references (a field a part names, a condition's fields, an id used twice) and expressions. Use the schema for completion and quick feedback, and validatePage to decide.

The browser's checks help the person filling the form. They are not a security boundary: the app's server checks what it is sent again, with checkSubmission(page, values) (see What Fieldia promises).

The mistakes the checks catch

Each row is a mistake agents make, with the words validatePage says, what a 0.36 viewer does with it, and how to fix it. checkPageWhole refuses every one, as validatePage does. A viewer refuses some before it draws the page, as 0.35's did. The rest it draws in 0.36, saying them in the console and to onError, and refuses them from 0.37.

MistakeWhat the check saysA 0.36 viewerWrite instead
A field typed emailfields.email.type: "type" is not one of the kinds allowed hererefuses it"type": "char", with "pattern" or a node's "widget": "email"
"required": "yes"fields.name.required: Invalid input: expected boolean, received stringdraws it, says it"required": true
Options as plain wordsfields.topic.options[0]: Invalid input: expected object, received stringdraws it, says it[{ "value": "sales", "label": "Sales" }]
A step setValueon.change.topic[0].do: "do" is not one of the kinds allowed heredraws it, says it{ "do": "set", "field": "seats", "value": "1" }
A key the format does not havefields.name: Unrecognized key: "read-only"draws it, says it"readonly": true
A part with no idlayout.children[0].id: Invalid input: expected string, received undefineddraws it, says itan id on every part, unique in the page
One id twicelayout.children[1]: duplicate id "f-name", also used at layout.children[0]refuses itanother id
A part naming a field the page lackslayout.children[4].field: no field "phone"refuses itthe field in fields first
A condition reading a field the page lackslayout.children[3].invisible: "kind != 'sales'" reads "kind", which is not a field of this pagerefuses ita field of the page
=== or && in a conditioncannot read "topic === 'sales'": Unexpected "=" at character 9refuses it==, and, or
Words in a value not quotedon.change.topic[0].value: cannot read "hello world": Unexpected token at position 1refuses it"value": "'hello world'"
A function that is not onefields.seats.compute: cannot read "lenght(name)": no function "lenght": the functions are round, abs, min, max, len, …refuses itone of the functions listed
Its least more than its mostfields.seats.min: the least (10) is more than the most (5): no value could be givendraws it, says itmin no more than max
A first value of another kindfields.seats.default: "five" is not a whole number: an integer field's first value is one, written as a numberdraws it, says it"default": 5
A first value that is not a choicefields.topic.default: "billing" is not one of the field's options: its first value is one of "sales", "support"draws it, says itone of the option values
An option's value twicefields.topic.options[2].value: "sales" is the value of an option before it: each option's value oncedraws it, says iteach value once
A list's column twicelayout.columns[1]: "name" is a column before it: each column oncedraws it, says iteach column once
A widget's option the format refuseslayout.children[1].options.countries: countries is "list" (Fieldia’s own, found by typing) or "native" (the browser’s own list)draws it, says itone of the values listed
No fieldiafieldia: "fieldia" says which format the page is written in: "0.13" for this Fieldiarefuses it"fieldia": "0.13", or stampPage(page)
A format newer than the readerfieldia: this page is in format 0.99, newer than this Fieldia reads (0.13): update Fieldia to show itrefuses ita format Fieldia has had

Two more are warnings: validatePage says them, the page is still drawn.

A worked example

An agent is asked for a contact form: a name and an email, both required, a topic, and the number of seats asked only when the topic is sales. Its first page has three mistakes:

{
  "fieldia": "0.13",
  "id": "contact",
  "title": "Contact us",
  "data": { "kind": "responses" },
  "fields": {
    "name": { "type": "char", "label": "Your name", "required": "yes" },
    "email": { "type": "email", "label": "Email", "required": true },
    "topic": { "type": "selection", "label": "Topic", "options": ["sales", "support"] },
    "seats": { "type": "integer", "label": "Seats", "min": 1, "max": 50 }
  },
  "layout": {
    "type": "sections",
    "id": "root",
    "children": [
      { "type": "field", "id": "f-name", "field": "name" },
      { "type": "field", "id": "f-email", "field": "email" },
      { "type": "field", "id": "f-topic", "field": "topic" },
      { "type": "field", "id": "f-seats", "field": "seats", "invisible": "topic != 'sales'" }
    ]
  }
}

validatePage answers:

fields.name.required: Invalid input: expected boolean, received string
fields.email.type: "type" is not one of the kinds allowed here
fields.topic.options[0]: Invalid input: expected object, received string
fields.topic.options[1]: Invalid input: expected object, received string

The agent fixes each one where its path points. It writes true. It makes the email a char with a pattern, and asks the browser to fill it in as an email. It writes each option as a value and a label:

{
  "fieldia": "0.13",
  "id": "contact",
  "title": "Contact us",
  "data": { "kind": "responses" },
  "fields": {
    "name": { "type": "char", "label": "Your name", "required": true },
    "email": { "type": "char", "label": "Email", "required": true, "pattern": "^[^@\\s]+@[^@\\s]+$" },
    "topic": {
      "type": "selection",
      "label": "Topic",
      "options": [
        { "value": "sales", "label": "Sales" },
        { "value": "support", "label": "Support" }
      ]
    },
    "seats": { "type": "integer", "label": "Seats", "min": 1, "max": 50 }
  },
  "layout": {
    "type": "sections",
    "id": "root",
    "children": [
      { "type": "field", "id": "f-name", "field": "name" },
      { "type": "field", "id": "f-email", "field": "email", "autocomplete": "email" },
      { "type": "field", "id": "f-topic", "field": "topic" },
      { "type": "field", "id": "f-seats", "field": "seats", "invisible": "topic != 'sales'" }
    ]
  }
}

validatePage now says ok: true. stampPage stamps the page "0.3", the format the box's autocomplete came in, so every Fieldia from 0.24 reads it. The app stores it, and a viewer draws it:

import { mountViewer } from '@fieldia/viewer';

mountViewer(document.getElementById('form')!, { page, dataSource, onError: (error) => report(error) });

Had the agent stored the first page, the viewer would have refused it before drawing it: its email field is of no kind Fieldia knows. The form's place would say "This form cannot be shown: its page has mistakes", with fields.email: a field needs a type Fieldia knows and a label under "What is wrong", and the app's onError would hear it. In React, Vue and Angular the app around it stays. Had the agent fixed that alone, a 0.36 viewer would draw the page and say its other three mistakes, once in the console and to onError; a 0.37 viewer refuses it.

Where to read more