# Field types

> Every field and layout element in Birch UI Forms, with its properties, the value it stores and an example.

Every element has a `type`. Fields store an answer under their `name`; layout elements arrange or explain. All fields also accept the [common field properties](https://docs.birchui.com/forms/schema.md#properties-of-every-field) such as `title`, `description`, `required`, `visibleIf` and `width`.

**Live demo: Service request form** (runs on the HTML version of this page). Source of `demos/form-renderer.ts`. Imports from `./_shared` and `./_scheduler-data` are sample data and small UI helpers used only by the docs.

```ts
import { createForm } from '@birchui/forms';
import { docsTheme, layout, onDocsThemeChange } from './_shared';
import { serviceRequest } from './_forms-data';

export const meta = { title: 'Service request form', height: 600 };

export default function mount(el: HTMLElement): () => void {
  const { toolbar, body, status } = layout(el);
  body.style.overflow = 'auto';
  body.style.padding = '16px';
  toolbar.append('Choose "Emergency" to reveal a conditional field. Add units on the second page.');

  const form = createForm(body, {
    schema: serviceRequest,
    data: { company: 'Kestrel Logistics', region: 'Europe' },
    theme: docsTheme(),
  });

  const offs = [
    form.on('valueChange', ({ name, value }) => {
      status.textContent = `${name} = ${JSON.stringify(value)}`;
    }),
    form.on('validate', ({ valid, errors }) => {
      status.textContent = valid
        ? 'All fields are valid.'
        : `${errors.length} field(s) need attention: ${errors.map((e) => e.label).join(', ')}`;
    }),
    form.on('formSubmit', ({ data }) => {
      status.textContent = `Submitted: ${JSON.stringify(data)}`;
    }),
  ];
  status.textContent = 'Values appear here as you type.';
  const stopTheme = onDocsThemeChange((theme) => form.update({ theme }));
  return () => {
    for (const off of offs) off();
    stopTheme();
    form.destroy();
  };
}
```

## Summary

| Type | Value | Notable properties |
| --- | --- | --- |
| `text` | string | `inputType`, `minLength`, `maxLength`, `pattern`, `patternMessage`, `autocomplete` |
| `email` | string | `maxLength`, `autocomplete` |
| `number` | number | `min`, `max`, `step`, `integer` |
| `textarea` | string | `rows`, `minLength`, `maxLength` |
| `select` | choice value | `choices`, `placeholder` |
| `multiselect` | array of choice values | `choices`, `minSelected`, `maxSelected` |
| `radio` | choice value | `choices`, `inline` |
| `checkbox` | boolean | `required` means it must be checked |
| `checkboxgroup` | array of choice values | `choices`, `inline`, `minSelected`, `maxSelected` |
| `toggle` | boolean | `onText`, `offText` |
| `date` | `'YYYY-MM-DD'` | `min`, `max` |
| `time` | `'HH:MM'` | `min`, `max`, `step` |
| `datetime` | `'YYYY-MM-DDTHH:MM'` | `min`, `max` |
| `rating` | number | `min`, `max`, `display`, `minLabel`, `maxLabel` |
| `slider` | number | `min`, `max`, `step`, `unit` |
| `file` | array of `File` | `accept`, `multiple`, `maxSize`, `maxFiles` |
| `signature` | data URL string | `height`, `penColor` |
| `matrix` | object of row value to column value | `rows`, `columns` |
| `hidden` | any | `defaultValue` |
| `computed` | expression result | `expression`, `format`, `currency`, `decimals`, `display` |
| `markdown` | none | `content` |
| `panel` | none; its fields write to the parent | `elements`, `collapsible`, `collapsed` |
| `dynamicpanel` | array of objects | `elements`, `templateTitle`, `minPanels`, `maxPanels`, `initialPanels`, `addText`, `removeText` |

## Text input

### `text`

A single-line input. `inputType` switches the browser control to `'tel'`, `'url'`, `'password'` or `'search'`, which brings the right keyboard on phones. `pattern` is a regular expression that must match the whole value.

```ts
{
  type: 'text',
  name: 'policyNumber',
  title: 'Policy number',
  required: true,
  pattern: 'HM-[0-9]{6}',
  patternMessage: 'Policy numbers look like HM-482913.',
  autocomplete: 'off',
}
```

Set `autocomplete` to the standard token, such as `'name'`, `'tel'` or `'postal-code'`, so browsers and password managers can fill the field.

### `email`

An email input with format validation. It sets `autocomplete="email"` unless you choose another token.

### `number`

A numeric input. `integer: true` allows only whole numbers and shows a numeric keypad on phones. The value is stored as a number.

```ts
{ type: 'number', name: 'mileage', title: 'Current mileage', min: 0, max: 999999, integer: true }
```

### `textarea`

Multi-line text. `rows` sets the initial height in lines, 4 by default.

## Choices

Choice lists are strings, numbers or `{ value, text, visibleIf }` objects. See [Choices](https://docs.birchui.com/forms/schema.md#choices).

### `select`

A dropdown. The empty first option shows `placeholder`, or "Select an option".

### `multiselect`

A list box that allows several selections. The value is an array of the selected values.

### `radio`

A group of radio buttons. `inline: true` lays the options out in a row, which suits short options such as Yes / No.

```ts
{ type: 'radio', name: 'policeReport', title: 'Was the incident reported to the police?', inline: true, choices: ['Yes', 'No'] }
```

### `checkboxgroup`

A group of checkboxes for "select all that apply". `minSelected` and `maxSelected` limit how many can be checked.

```ts
{
  type: 'checkboxgroup',
  name: 'damagedItems',
  title: 'What was damaged?',
  minSelected: 1,
  choices: ['Windows', 'Roof', 'Flooring', 'Furniture', 'Electronics'],
}
```

### `checkbox`

A single checkbox, usually for consent. Its value is `true` or `false`, and `required: true` means it must be checked.

### `toggle`

An on/off switch with the `switch` role. `onText` and `offText` replace the default "On" and "Off" state labels.

## Dates and times

`date`, `time` and `datetime` use the browser's native pickers and store ISO strings: `'2026-11-14'`, `'14:30'` and `'2026-11-14T14:30'`. `min` and `max` are ISO strings in the same format.

```ts
{ type: 'date', name: 'dateOfLoss', title: 'Date of loss', required: true, max: '2026-12-31' }
```

For a limit relative to today, use an [expression validator](https://docs.birchui.com/forms/validation.md#expression-validators), such as `{dateOfLoss} <= today()`.

## Scales

### `rating`

A row of choices from `min` to `max`, 1 to 5 by default, shown as stars or, with `display: 'numbers'`, as numbers. `minLabel` and `maxLabel` label the ends of the scale. Each choice is a native radio button, so it works with the keyboard and screen readers.

```ts
{
  type: 'rating',
  name: 'technicianRating',
  title: 'How would you rate the technician?',
  display: 'numbers',
  min: 0,
  max: 10,
  minLabel: 'Not likely',
  maxLabel: 'Very likely',
}
```

### `slider`

A range slider, 0 to 100 by default, with an optional `unit` shown after the value, such as `'%'` or `'km'`. Until the user moves it, the slider has no value and reads "Not set".

## Files and signatures

### `file`

A file picker. The value is an array of `File` objects, even when `multiple` is off. `accept` uses the same syntax as the HTML attribute: extensions such as `'.pdf'`, MIME types such as `'application/pdf'`, or wildcards such as `'image/*'`. `maxSize` is in bytes and `maxFiles` limits the number of files. Picking the same file twice adds it once.

```ts
{
  type: 'file',
  name: 'receipts',
  title: 'Receipts or invoices',
  accept: '.pdf,image/*',
  multiple: true,
  maxFiles: 10,
  maxSize: 15_000_000,
}
```

The renderer does not upload files. Send them with `FormData` when the form is submitted, as shown in the [overview](https://docs.birchui.com/forms/overview.md#a-first-form).

### `signature`

A signature pad for mouse, pen or touch. Users who cannot draw can choose **Type instead** and type their name. The value is an image as a data URL: a PNG, or SVG where the canvas is not available. `height` sets the pad height in pixels, between 80 and 400 (180 by default), and `penColor` the ink colour.

## Grids of questions

### `matrix`

A table of radio buttons that asks the same question for several rows. The value maps each row's value to the chosen column's value. When the matrix is required, every row must be answered.

```ts
{
  type: 'matrix',
  name: 'serviceQuality',
  title: 'How satisfied were you with each part of the visit?',
  rows: [
    { value: 'booking', text: 'Booking the appointment' },
    { value: 'punctuality', text: 'Arrival on time' },
    { value: 'repair', text: 'Quality of the repair' },
  ],
  columns: ['Poor', 'Fair', 'Good', 'Excellent'],
  required: true,
}
// value: { booking: 'Good', punctuality: 'Excellent', repair: 'Good' }
```

## Values without input

### `hidden`

Stores a value without showing anything, such as a source campaign or a record id. Set it with `defaultValue`, through `data`, or with `form.setValue()`. Hidden fields are never validated.

```ts
{ type: 'hidden', name: 'branchCode', defaultValue: 'LDN-04' }
```

### `computed`

Shows the result of an [expression](https://docs.birchui.com/forms/expressions.md) and stores it as an answer. It updates as the user types, and its value is included in the submitted data.

```ts
{
  type: 'computed',
  name: 'claimTotal',
  title: 'Total claimed',
  expression: 'sum({lineItems.amount})',
  format: 'currency',
  currency: 'GBP',
  decimals: 2,
}
```

| `format` | Shows `1234.5` as (in `en-GB`) |
| --- | --- |
| `'number'` (default) | `1,234.5` |
| `'currency'` | `£1,234.50`, using `currency` (default `'USD'`) |
| `'percent'` | `123,450%`; store fractions such as `0.25` for 25% |
| `'text'` | `1234.5`, unformatted |

`decimals` fixes the number of decimal places. Set `display: false` to compute and submit a value without showing it. An empty or invalid result shows a dash and stores nothing. Computed fields can depend on each other; a circular reference is reported through `formError`.

## Layout

### `markdown`

A block of text between questions, for instructions or legal notes. `content` supports `**bold**`, `*italic*`, `` `code` ``, links, bulleted and numbered lists, and headings with `#`, `##` and `###`. `{fieldName}` inserts the current answer of a field. HTML is shown as text, not rendered, and links are limited to `http`, `https`, `mailto`, `tel`, relative and in-page URLs.

```ts
{
  type: 'markdown',
  content: 'Thanks, {firstName}. Before you continue, read our [claims guide](https://example.com/claims-guide).',
}
```

### `panel`

Groups related fields under a heading, drawn as a `fieldset` with a `legend`. A panel's `visibleIf` and `enableIf` apply to all of its fields, which is the easiest way to show a whole block conditionally. `collapsible: true` lets users fold it, and `collapsed: true` starts it folded.

```ts
{
  type: 'panel',
  title: 'Vehicle details',
  visibleIf: "{claimType} = 'motor'",
  elements: [
    { type: 'text', name: 'registration', title: 'Registration', width: 'half' },
    { type: 'text', name: 'make', title: 'Make and model', width: 'half' },
  ],
}
```

Panels do not need a name, and their fields write to the same data object as the fields around them.

### `dynamicpanel`

A repeating section, where users add as many entries as they need: dependants, previous employers, line items. See [Repeating sections](https://docs.birchui.com/forms/dynamic-panels.md).

## Type reference

Each field type has its own interface, such as `TextField`, `NumberField` or `ComputedField`; the union of all of them is `FieldSchema`, and `ElementSchema` adds the layout elements. They are listed in the [API reference](https://docs.birchui.com/api/forms.md).
