Options

Options

A choice offers a written list, or a list from your API.

A written list

Each option has a code, which the API receives, and a label, which people read.

{
  key: "kind",
  type: "radio",
  label: "Kind",
  options: [
    { code: "COFFEE", label: "Coffee" },
    { code: "TEA", label: "Tea" },
  ],
}

Picking several

checkboxes takes the same options and lets people tick as many as they like. The answer is a list of codes.

{
  key: "extras",
  type: "checkboxes",
  label: "What else do you sell?",
  options: [
    { code: "SNACKS", label: "Snacks" },
    { code: "CAKES", label: "Cakes" },
  ],
}
// extras: ["SNACKS", "CAKES"]

A required one needs at least one tick. For a long list, type: "select" with multiple: true takes several picks from a dropdown.

Try it in the tutorial: Picking several.

A dictionary

A dictionary is a list your API serves. Define it once and import it where it is used.

import { defineDictionary, dictionaryPathV1 } from "#form-engine";

export const menuItems = defineDictionary({
  params: ["service"],
  path: ({ service }) => dictionaryPathV1(`demo/${service}/menu`),
});
options: {
  dictionary: menuItems,
  params: { service: "CAFE" },
}

from fills params from other answers in the same section, and waits until they are given:

options: {
  dictionary: districts,
  from: { province: "province" },
}

Long lists

appearance: "dialog" opens a searchable list, grouped, chosen with a click or the arrow keys.