JSON Forms Extended

Example: array controls

Example ID: array-controls
Demo entry: Spec: Array controls (#spec-array-controls)
Domain: conference programme
Specs covered:

One schema, five presentations, one tab each. The example exists to make the selection rules visible rather than described, because that is the part that surprises people: you do not pick an array renderer by naming it, except when you do.

Tab Array Chosen because
Table sessions It nests a room, which would normally win the detail renderer — options.table overrides that.
Expandable speakers, announcements The items nest. No option asks for this; the shape decides.
List with detail sponsors type: "ListWithDetail". An element type, not a Control option.
AG Grid tickets options.variant: "ag-grid", naming the renderer outright.
Add, remove and bounds rounds, checklist, reviewers Three different ways of being told what may change.

Files

File Role
schema.json Eight arrays: flat rows, nested rows, nested arrays, bounds, and a contains.
uischema.json The five tabs. Plain JSON throughout — nothing here is composed in TypeScript.
data.json Enough to fill every presentation, and one deliberate failure (no lead reviewer).
config.json restrict: true, which is what turns minItems/maxItems into prevention.
translations.json English and Bulgarian, including the tab labels.

Table: an explicit request beats the ranking

sessions items contain a nested room object. Ordinary selection prefers the expandable presentation for that shape, so a table has to be asked for:

{ "type": "Control", "scope": "#/properties/sessions",
  "options": { "table": true, "cells": { "room": { "summary": …, "detail": … } } } }

The nested property stays a column. It is not flattened and it is not dropped: cells.room gives the column a one-line summary and a detail dialog.

summary is a scoped control, not a format string:

"summary": { "type": "Control", "scope": "#/properties/name" }

For an object it resolves that one property; for an array it previews up to two values and adds "+N more". There is no interpolation syntax — writing "{name} · floor {floor}" produces the literal fallback, which is how this example's first draft ended up displaying {}.

Expandable: two controls, opposite options

The first speakers control takes the defaults. The second, announcements, inverts every one of them, so the options are visible side by side rather than only described:

Option speakers announcements
collapsed default — the first item opens true — everything starts closed
collapseNewItems default — a new item opens true — a new item stays closed
hideAvatar default — the index marker shows true — marker gone, index still readable
hideArraySummaryValidation default — child summary shows true — summary hidden, validation unchanged
elementLabelProp name text
showSortButtons true — Move up/down default — no reorder

elementLabelProp is an item-relative data path, not a JSON pointer. Headers read "Rosa Iqbal", not "Item 1".

List with detail

Selected by type: "ListWithDetail". Nothing about sponsors' schema asks for it, and no Control option can produce it — which is the point of including it beside the other four. Pick an item on the left; the form on the right edits that item's own data path.

AG Grid

tickets also nests, and the spec is explicit that this must not push an explicitly selected grid into another presentation:

Nested item properties must not force this explicitly selected grid into ListWithDetail or expandable-item presentation.

Two things about the grid are easy to get wrong when reading its output:

Add, remove and bounds

Three arrays, three different reasons an action may be unavailable — which is worth separating, because they are unrelated mechanisms.

Array Mechanism Effect
rounds minItems: 1, maxItems: 3 + restrict Delete refused at one, Add refused at three.
checklist disableAdd, disableRemove Both actions gone regardless of size; fields stay editable.
reviewers neither Both actions available — the contrast that makes the other two mean something.

In every case the handler is guarded too, not just the button. The spec requires it, and a disabled button is reachable anyway through a keyboard or a stale DOM node.

What Add actually creates

rounds items are the spec's own worked example: a required name and an active with a default. Add produces

{ "active": true }

and the missing name stays an error. Initialization declares defaults; it does not invent a valid item, and it is not a satisfiability solver.

contains: an error that belongs to no item

reviewers must contain a lead:

"contains": {
  "type": "object",
  "required": ["lead"],
  "properties": { "lead": { "const": true } }
}

The required matters — without it, { "name": "Ada" } would count as a match. The failure is reported against the array, and it is reported for an empty array too, where there is no item to hang it on.

One thing to expect when reading the raw validator output: Ajv also reports the contains subschema's own failures at item paths, so a single reviewer without lead produces three errors, not one:

/reviewers/0        required   must have required property 'lead'
/reviewers          contains   must contain at least 1 valid item(s)

Those item-path entries are an artefact of how contains is evaluated, not a claim that each reviewer is required to be a lead. Presentation should not repeat them as if they were.

minContains/maxContains are deliberately not used here. They require draft 2019-09 or later; this example validates under the demo's default dialect, where they would be silently inert — which would make the example teach something false.

Expected behaviour

Action Result
Open Table Sessions in rows; Room is a column showing "Aurora", not an inline form.
Click a Room cell A detail dialog, not an expanding row.
Open Expandable Speakers with the first item open; announcements all closed.
Edit a speaker's name The panel header follows it.
Open AG Grid, sort a column The order on screen changes; the stored array does not, and the drag handle withdraws.
Press Delete on the only round Refused — the button is disabled and the handler declines.
Press Add on rounds three times Two items are added as {"active": true}, then Add is refused.
Look at the opening checklist No Add, no Delete, every field still editable.
Clear the lead reviewer An array-level error appears on the array, not on a row.

Conformance scope

This walkthrough describes the portable contract. Renderer support must be checked by a host adapter; the package validates the authored assets, not live UI behavior.

Scalar and composite cells

The Scalar and composite cells tab shows the same conference staff array as a table and a grid. It covers strings, integers, enum choices, colors, durations, dates, times, date-times, booleans, objects and arrays. A change in one view is visible in the other because both edit staff.

Address summaries use the street; phone summaries use the array itself. Open either detail dialog, edit the draft, then cancel or apply it. cells.<property>.showEmptyButton requests a Clear action inside the dialog; clearing a draft must not commit until Apply. This supplements the existing Room and Holder detail examples with an array-valued cell.

The grid supplies explicit column widths, disables filtering on composite and boolean columns, and enables pagination. A page size of one makes the second page visible with only two records; the selector offers 1, 2 and 10 rows. showSortButtons requests row dragging, which is unavailable while the view is sorted or filtered. Page changes and view sorting must not reorder form data.

The added staff records are schema-valid and add no initial validation errors. An adapter without a matching specialized cell must preserve the stored value; a fallback is not evidence that its specialized editing behavior is supported.

Standalone host setup

Load the JSON assets listed in the catalog into a host with the relevant renderer capabilities. No framework registration module is required by this package.

All array presentations enable collapsible. Use the header toggle to hide and restore the panel body without losing data or item expansion. Set collapsed: true to start closed; item collapsed remains independent.

The reviewers contains rule requires at least one entry with lead: true. The field-specific arrayControls.reviewers.error.contains translation explains how to fix that array error in English and Bulgarian, without overriding other contains messages or requiring the ajv-errors plugin.

The Reviewers control explicitly declares i18n: "arrayControls.reviewers", so the custom error message is scoped to this example rather than the generic reviewers data path.

Consolidated demo coverage

Staff cells include an alpha color and a composite address with a nested horizontal layout. Both the table and grid share these cell details.

Row and cell editing

The Row and cell dialogs, Side panel, and Bottom panel tabs edit the same Sessions data. Row details include Title, Track, Minutes and Room; the Room cell has an independent detail editor. Both dialog types explicitly enable draggable, resizable and maximizable. Drag the header, use the resize corner, and maximize/restore from the header. Dialog changes are drafts until Apply; Cancel discards them. Panel edits apply immediately. The bottom panel starts collapsed.

Acceptance: edit a Room in its cell dialog, cancel, then apply; repeat through the row dialog. Exercise geometry controls on both dialogs. Compare immediate edits in the side and bottom panels and verify sibling rows stay unchanged.