Skip to contents

Forms

A guide to building forms with Base UI components.

Base UI form control components extend the native constraint validation API so you can build forms for collecting user input or providing control over an interface. Their controlled values and validation state can be integrated with form libraries such as Formisch and TanStack Form. Neither library supports Solid 2.0 yet, so these demos use small local helpers that mirror each library’s API until it does.

Must be 3 or more characters long

Enter a registry URL with optional tags

Server type
Scaling threshold
20% – 80%
Storage type
Allowed network protocols
import { For } from 'solid-js';
import type { Accessor } from 'solid-js';
import type { JSX } from '@solidjs/web';
import { Button } from './button';
import { CheckboxGroup } from './checkbox-group';
import { Form } from './form';
import { RadioGroup } from './radio-group';
import { ToastProvider, useToastManager } from './toast';
import * as Autocomplete from './autocomplete';
import * as Checkbox from './checkbox';
import * as Combobox from './combobox';
import * as Field from './field';
import * as Fieldset from './fieldset';
import * as NumberField from './number-field';
import * as Radio from './radio';
import * as Select from './select';
import * as Slider from './slider';
import * as Switch from './switch';

function ExampleForm() {
  const toastManager = useToastManager();
  return (
    <Form
      aria-label="Launch new cloud server"
      onFormSubmit={(formValues) => {
        toastManager.add({
          title: 'Form submitted',
          description: 'The form contains these values:',
          data: formValues,
        });
      }}
    >
      <Field.Root name="serverName">
        <Field.Label>Server name</Field.Label>
        <Field.Control
          defaultValue=""
          placeholder="e.g. api-server-01"
          required
          minlength={3}
          pattern=".*[A-Za-z].*"
        />
        <Field.Description>Must be 3 or more characters long</Field.Description>
        <Field.Error />
      </Field.Root>

      <Field.Root name="region">
        <Combobox.Root items={REGIONS} required>
          <div class="relative text-sm leading-5 font-bold text-neutral-950 dark:text-white">
            <Field.Label class="mb-1 block">Region</Field.Label>
            <Combobox.InputGroup>
              <Combobox.Input placeholder="e.g. eu-central-1" />
              <div class="absolute right-0 bottom-0 inline-flex h-full items-center justify-center text-neutral-500 dark:text-neutral-400">
                <Combobox.Clear />
                <Combobox.Trigger>
                  <Combobox.CaretDownIcon />
                </Combobox.Trigger>
              </div>
            </Combobox.InputGroup>
          </div>
          <Combobox.Portal>
            <Combobox.Positioner>
              <Combobox.Popup>
                <Combobox.Empty>No matches</Combobox.Empty>
                <Combobox.List>
                  {(region: Accessor<string>) => {
                    return (
                      <Combobox.Item value={region()}>
                        <Combobox.ItemIndicator>
                          <CheckIcon />
                        </Combobox.ItemIndicator>
                        <span class="col-start-2">{region()}</span>
                      </Combobox.Item>
                    );
                  }}
                </Combobox.List>
              </Combobox.Popup>
            </Combobox.Positioner>
          </Combobox.Portal>
        </Combobox.Root>
        <Field.Error />
      </Field.Root>

      <Field.Root name="containerImage">
        <Autocomplete.Root
          items={IMAGES}
          mode="both"
          itemToStringValue={(itemValue: Image) => itemValue.url}
          required
        >
          <Field.Label>Container image</Field.Label>
          <Autocomplete.Input placeholder="e.g. docker.io/library/node:latest" />
          <Field.Description>Enter a registry URL with optional tags</Field.Description>
          <Autocomplete.Portal>
            <Autocomplete.Positioner>
              <Autocomplete.Popup>
                <Autocomplete.List>
                  {(image: Accessor<Image>) => {
                    return (
                      <Autocomplete.Item value={image()}>
                        <span>{image().name}</span>
                        <span class="font-mono whitespace-nowrap text-xs opacity-80">
                          {image().url}
                        </span>
                      </Autocomplete.Item>
                    );
                  }}
                </Autocomplete.List>
              </Autocomplete.Popup>
            </Autocomplete.Positioner>
          </Autocomplete.Portal>
        </Autocomplete.Root>
        <Field.Error />
      </Field.Root>

      <Field.Root name="serverType">
        <Select.Root items={SERVER_TYPES} required>
          <div class="w-fit space-y-1">
            <Select.Label>Server type</Select.Label>
            <Select.Trigger class="w-48">
              <Select.Value />
              <Select.Icon>
                <CaretUpDownIcon />
              </Select.Icon>
            </Select.Trigger>
          </div>
          <Select.Portal>
            <Select.Positioner>
              <Select.Popup>
                <Select.ScrollUpArrow />
                <Select.List>
                  <For each={SERVER_TYPES}>
                    {({ label, value }) => {
                      return (
                        <Select.Item value={value}>
                          <Select.ItemIndicator>
                            <CheckIcon />
                          </Select.ItemIndicator>
                          <Select.ItemText>{label}</Select.ItemText>
                        </Select.Item>
                      );
                    }}
                  </For>
                </Select.List>
                <Select.ScrollDownArrow />
              </Select.Popup>
            </Select.Positioner>
          </Select.Portal>
        </Select.Root>
        <Field.Error />
      </Field.Root>

      <Field.Root name="numOfInstances">
        <NumberField.Root defaultValue={undefined} min={1} max={64} required>
          <Field.Label>Number of instances</Field.Label>
          <NumberField.Group>
            <NumberField.Decrement>
              <MinusIcon />
            </NumberField.Decrement>
            <NumberField.Input />
            <NumberField.Increment>
              <PlusIcon />
            </NumberField.Increment>
          </NumberField.Group>
        </NumberField.Root>
        <Field.Error />
      </Field.Root>

      <Field.Root name="scalingThreshold">
        <Fieldset.Root
          render={(renderProps) => (
            <Slider.Root
              defaultValue={[0.2, 0.8]}
              thumbAlignment="edge"
              min={0}
              max={1}
              step={0.01}
              format={{
                style: 'percent',
                minimumFractionDigits: 0,
                maximumFractionDigits: 0,
              }}
              class="w-full gap-y-2"
              {...(renderProps as any)}
            />
          )}
        >
          <Fieldset.Legend>Scaling threshold</Fieldset.Legend>
          <Slider.Value class="col-start-2 text-end" />
          <Slider.Control>
            <Slider.Track>
              <Slider.Indicator />
              <Slider.Thumb index={0} aria-label="Minimum threshold" />
              <Slider.Thumb index={1} aria-label="Maximum threshold" />
            </Slider.Track>
          </Slider.Control>
        </Fieldset.Root>
      </Field.Root>

      <Field.Root name="storageType">
        <Fieldset.Root
          render={(renderProps) => (
            <RadioGroup<'ssd' | 'hdd'> class="gap-4" defaultValue="ssd" {...(renderProps as any)} />
          )}
        >
          <Fieldset.Legend class="-mt-px">Storage type</Fieldset.Legend>
          <Field.Item>
            <Field.Label>
              <Radio.Root value="ssd">
                <Radio.Indicator />
              </Radio.Root>
              SSD
            </Field.Label>
          </Field.Item>
          <Field.Item>
            <Field.Label>
              <Radio.Root value="hdd">
                <Radio.Indicator />
              </Radio.Root>
              HDD
            </Field.Label>
          </Field.Item>
        </Fieldset.Root>
      </Field.Root>

      <Field.Root name="restartOnFailure">
        <Field.Label class="gap-2">
          Restart on failure
          <Switch.Root defaultChecked>
            <Switch.Thumb />
          </Switch.Root>
        </Field.Label>
      </Field.Root>

      <Field.Root name="allowedNetworkProtocols">
        <Fieldset.Root
          render={(renderProps) => <CheckboxGroup defaultValue={[]} {...(renderProps as any)} />}
        >
          <Fieldset.Legend class="mb-2">Allowed network protocols</Fieldset.Legend>
          <div class="flex gap-4">
            <For each={['http', 'https', 'ssh']}>
              {(val) => {
                return (
                  <Field.Item>
                    <Field.Label class="uppercase">
                      <Checkbox.Root value={val}>
                        <Checkbox.Indicator>
                          <CheckIcon />
                        </Checkbox.Indicator>
                      </Checkbox.Root>
                      {val}
                    </Field.Label>
                  </Field.Item>
                );
              }}
            </For>
          </div>
        </Fieldset.Root>
      </Field.Root>

      <Button type="submit" class="mt-3">
        Launch server
      </Button>
    </Form>
  );
}

export default function App() {
  return (
    <ToastProvider>
      <ExampleForm />
    </ToastProvider>
  );
}

function CaretUpDownIcon(props: JSX.IntrinsicElements['svg']) {
  return (
    <svg
      width="16"
      height="16"
      viewBox="0 0 16 16"
      fill="currentColor"
      {...props}
      style={props.style}
    >
      <path d="M11 10H5l3 3.5zm0-4H5l3-3.5z" />
    </svg>
  );
}

function CheckIcon(props: JSX.IntrinsicElements['svg']) {
  return (
    <svg
      width="16"
      height="16"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      {...props}
      style={props.style}
    >
      <path d="m2.5 8.5 4 4 7-9" />
    </svg>
  );
}

function PlusIcon(props: JSX.IntrinsicElements['svg']) {
  return (
    <svg
      width="16"
      height="16"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      stroke-linecap="square"
      stroke-linejoin="round"
      {...props}
      style={props.style}
    >
      <path d="M1.5 8h13M8 14.5v-13" />
    </svg>
  );
}

function MinusIcon(props: JSX.IntrinsicElements['svg']) {
  return (
    <svg
      width="16"
      height="16"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      stroke-linecap="square"
      stroke-linejoin="round"
      {...props}
      style={props.style}
    >
      <path d="M1.5 8h13" />
    </svg>
  );
}

function cartesian<T extends string[][]>(...arrays: T): string[][] {
  return arrays.reduce<string[][]>(
    (acc, curr) => acc.flatMap((a) => curr.map((b) => [...a, b])),
    [[]],
  );
}

const REGIONS = cartesian(['us', 'eu', 'ap'], ['central', 'east', 'west'], ['1', '2', '3']).map(
  (part) => part.join('-'),
);

interface Image {
  url: string;
  name: string;
}
/* prettier-ignore */
const IMAGES: Image[] = ['nginx:1.29-alpine', 'node:22-slim', 'postgres:18', 'redis:8.2.2-alpine'].map((name) => ({
  url: `docker.io/library/${name}`,
  name,
}));

const SERVER_TYPES = [
  { label: 'Select server type', value: null },
  ...cartesian(['t', 'm'], ['1', '2'], ['small', 'medium', 'large']).map((part) => {
    const value = part.join('.').replace('.', '');
    return { label: value, value };
  }),
];

Naming form controls

Form controls must have an accessible name in order to be recognized by assistive technologies. Use the label strategy below for each control type.

Input controls

Use <Field.Label> or a native <label> to label the following controls:

  • Input
  • NumberField
  • OTPField
  • Autocomplete
  • Combobox (input outside popup)
  • Checkbox
  • Radio
  • Switch

You can implicitly label <Checkbox>, <Radio> and <Switch> components by enclosing them with <Field.Label>:

Implicitly labeling a switch
import { Field } from 'base-ui-solid/field';
import { Switch } from 'base-ui-solid/switch';

<Field.Root>
  <Field.Label>
    <Switch.Root />
    Developer mode
  </Field.Label>
  <Field.Description>Enables extra tools for web developers</Field.Description>
</Field.Root>;

Trigger-based controls

  • Combobox (input inside popup): use <Combobox.Label>.
  • Select: use <Select.Label>.
  • Slider: use <Slider.Label>. For multi-thumb sliders, also add an aria-label on each <Slider.Thumb> to distinguish the thumbs.

Fallback

If no visible label is rendered, provide aria-label on the actual form control.

Describing the control

<Field.Description> automatically assigns an accessible description:

Labeling select and slider
import { Form } from 'base-ui-solid/form';
import { Field } from 'base-ui-solid/field';
import { Select } from 'base-ui-solid/select';
import { Slider } from 'base-ui-solid/slider';

<Form>
  <Field.Root>
    <Select.Root>
      <Select.Label>Time zone</Select.Label>
      <Select.Trigger />
    </Select.Root>
    <Field.Description>Used for notifications and reminders</Field.Description>
  </Field.Root>

  <Field.Root>
    <Slider.Root defaultValue={50}>
      <Slider.Label>Zoom level</Slider.Label>
      <Field.Description>Adjust the size of the user interface</Field.Description>
      <Slider.Control>
        <Slider.Track>
          <Slider.Thumb />
        </Slider.Track>
      </Slider.Control>
    </Slider.Root>
  </Field.Root>
</Form>;

Labeling control groups

Compose <Fieldset> when labeling a group of controls, such as a range slider with multiple thumbs or a section that combines several inputs. For checkbox and radio groups, keep the group label in <Fieldset.Legend> and wrap each option with <Field.Item>:

Composing range slider and radio group with fieldset
import { Form } from 'base-ui-solid/form';
import { Field } from 'base-ui-solid/field';
import { Fieldset } from 'base-ui-solid/fieldset';
import { Radio } from 'base-ui-solid/radio';
import { RadioGroup } from 'base-ui-solid/radio-group';
import { Slider } from 'base-ui-solid/slider';

<Form>
  <Field.Root>
    <Fieldset.Root render={(props) => <Slider.Root defaultValue={[25, 75]} {...props} />}>
      <Fieldset.Legend>Price range</Fieldset.Legend>
      <Slider.Control>
        <Slider.Track>
          <Slider.Thumb index={0} aria-label="Minimum price" />
          <Slider.Thumb index={1} aria-label="Maximum price" />
        </Slider.Track>
      </Slider.Control>
    </Fieldset.Root>
  </Field.Root>

  <Field.Root>
    <Fieldset.Root render={(props) => <RadioGroup {...props} />}>
      <Fieldset.Legend>Storage type</Fieldset.Legend>
      <Field.Item>
        <Field.Label>
          <Radio.Root value="ssd" />
          SSD
        </Field.Label>
      </Field.Item>
      <Field.Item>
        <Field.Label>
          <Radio.Root value="hdd" />
          HDD
        </Field.Label>
      </Field.Item>
    </Fieldset.Root>
  </Field.Root>
</Form>;

<Field.Item> should enclose each checkbox or radio option so every control has its own label and description:

Explicitly labeling checkboxes in a checkbox group
import { Form } from 'base-ui-solid/form';
import { Field } from 'base-ui-solid/field';
import { Fieldset } from 'base-ui-solid/fieldset';
import { Checkbox } from 'base-ui-solid/checkbox';
import { CheckboxGroup } from 'base-ui-solid/checkbox-group';

<Field.Root>
  <Fieldset.Root render={(props) => <CheckboxGroup {...props} />}>
    <Fieldset.Legend>Backup schedule</Fieldset.Legend>
    <Field.Item>
      <Checkbox.Root value="daily" />
      <Field.Label>Daily</Field.Label>
      <Field.Description>Daily at 00:00</Field.Description>
    </Field.Item>
    <Field.Item>
      <Checkbox.Root value="monthly" />
      <Field.Label>Monthly</Field.Label>
      <Field.Description>On the 5th of every month at 23:59</Field.Description>
    </Field.Item>
  </Fieldset.Root>
</Field.Root>;

Building form fields

Pass the name prop to <Field.Root> to include the wrapped control’s value when a parent form is submitted:

Assigning field name to combobox
import { Form } from 'base-ui-solid/form';
import { Field } from 'base-ui-solid/field';
import { Combobox } from 'base-ui-solid/combobox';

<Form>
  <Field.Root name="country">
    <Field.Label>Country of residence</Field.Label>
    <Combobox.Root />
  </Field.Root>
</Form>;

Submitting data

You can take over form submission using the native onSubmit, or custom onFormSubmit props:

Native submission using onSubmit
import { Form } from 'base-ui-solid/form';

<Form
  onSubmit={async (event) => {
    // Prevent the browser's default full-page refresh
    event.preventDefault();
    // Create a FormData object
    const formData = new FormData(event.currentTarget);
    // Send the FormData instance in a fetch request
    await fetch('https://api.example.com', {
      method: 'POST',
      body: formData,
    });
  }}
/>;

When using onFormSubmit, you receive form values as a JavaScript object, with eventDetails provided as a second argument. Additionally, preventDefault() is automatically called on the native submit event:

Submission using onFormSubmit
import { Form } from 'base-ui-solid/form';

<Form
  onFormSubmit={async (formValues) => {
    const payload = {
      product_id: formValues.id,
      order_quantity: formValues.quantity,
    };
    await fetch('https://api.example.com', {
      method: 'POST',
      body: JSON.stringify(payload),
    });
  }}
/>;

Constraint validation

Base UI form components support native HTML validation attributes for many validation rules:

  • required specifies a required field.
  • minlength and maxlength specify a valid length for text fields.
  • pattern specifies a regular expression that the field value must match.
  • step specifies an increment that numeric field values must be an integral multiple of.
Defining constraint validation on a text field
import { Field } from 'base-ui-solid/field';

<Field.Root name="website">
  <Field.Control type="url" required pattern="https?://.*" />
  <Field.Error />
</Field.Root>;

Base UI form components use a hidden input to participate in native form submission and validation. To anchor the hidden input near a control so the native validation bubble points to the correct area, ensure the component has been given a name, and wrap controls in a relatively positioned container for best results.

Positioning hidden inputs
import { Field } from 'base-ui-solid/field';
import { Select } from 'base-ui-solid/select';

<Field.Root name="apple">
  <Select.Root>
    <Select.Label>Apple</Select.Label>
    <div class="relative">
      <Select.Trigger />
    </div>
  </Select.Root>
</Field.Root>;

Custom validation

You can add custom validation logic by passing a synchronous or asynchronous validation function to the validate prop, which runs after native validations have passed.

Use the validationMode prop to configure when validation is performed:

  • onSubmit (default) validates all fields when the containing <Form> is submitted, afterwards invalid fields revalidate when their value changes.
  • onFocusOut validates the field when focus moves away.
  • onChange validates the field when the value changes, for example, after each keypress in a text field or when a checkbox is checked or unchecked.

validationDebounceTime can be used to debounce the function in use cases such as asynchronous requests or text fields that validate onChange.

Text input using custom asynchronous validation
import { Field } from 'base-ui-solid/field';

<Field.Root
  name="username"
  validationMode="onChange"
  validationDebounceTime={300}
  validate={async (value) => {
    if (value === 'admin') {
      /* return an error message when invalid */
      return 'Reserved for system use.';
    }

    const result = await fetch(
      {/* prettier-ignore */},
      /* check the availability of a username from an external API */
    );

    if (!result) {
      return `${value} is unavailable.`;
    }

    /* return `null` when valid */
    return null;
  }}
>
  <Field.Control required minlength={3} />
  <Field.Error />
</Field.Root>;

Server-side validation

You can pass errors returned by (post-submission) server-side validation to the errors prop, which will be merged into the client-side field state for display.

This should be an object with field names as keys, and an error string or array of strings as the value. Once a field’s value changes, any corresponding error in errors will be cleared from the field state.

Displaying errors returned by server-side validation
import { createSignal } from 'solid-js';
import { Form } from 'base-ui-solid/form';
import { Field } from 'base-ui-solid/field';

async function submitToServer(/* payload */) {
  return {
    errors: {
      promoCode: 'This promo code has expired',
    },
  };
}

const [errors, setErrors] = createSignal<Form.Props['errors']>();

<Form
  errors={errors()}
  onSubmit={async (event) => {
    event.preventDefault();
    const response = await submitToServer(/* data */);
    setErrors(response.errors);
  }}
>
  <Field.Root name="promoCode" />
</Form>;

To get errors from the server, use an async submit handler (or the server-function integration provided by your Solid framework) and pass the returned field errors to errors.

Returning server errors in Solid
import { createSignal } from 'solid-js';
import { Form } from 'base-ui-solid/form';
import { Field } from 'base-ui-solid/field';
import { login } from './actions';

function LoginForm() {
  const [errors, setErrors] = createSignal<Form.Props['errors']>({});
  return (
    <Form
      errors={errors()}
      onSubmit={async (event) => {
        event.preventDefault();
        const result = await login(new FormData(event.currentTarget));
        setErrors(result.errors ?? {});
      }}
    >
      <Field.Root name="password">
        <Field.Control type="password" />
        <Field.Error />
      </Field.Root>
    </Form>
  );
}

Displaying errors

Use <Field.Error> without children to automatically display the field’s native error message when invalid. The match prop can be used to customize the message based on the validity state, and manage internationalization from your application logic:

Customizing error message for a required field
<Field.Error match="valueMissing">You must create a username</Field.Error>

Formisch

Formisch (@formisch/solid) is a schema-based form library for Solid that validates with Valibot. The demo below uses a small local helper (included in its source) that mirrors the Formisch and Valibot APIs it needs, and wires the field state to Base UI’s Field props.

Must be 3 or more characters long

Enter a registry URL with optional tags

Server type
Scaling threshold
20% – 80%
Storage type
Allowed network protocols
import { For } from 'solid-js';
import type { Accessor } from 'solid-js';
import type { JSX } from '@solidjs/web';
import { Button } from './button';
import { CheckboxGroup } from './checkbox-group';
import { Form } from './form';
import { RadioGroup } from './radio-group';
import { ToastProvider, useToastManager } from './toast';
import * as Autocomplete from './autocomplete';
import * as Checkbox from './checkbox';
import * as Combobox from './combobox';
import * as Field from './field';
import * as Fieldset from './fieldset';
import * as NumberField from './number-field';
import * as Radio from './radio';
import * as Select from './select';
import * as Slider from './slider';
import * as Switch from './switch';
// A local stand-in mirroring `@formisch/solid` and `valibot` until they support Solid 2.0.
import { createForm, Field as FormField, handleSubmit, v } from './local-formisch';
import type { InferOutput } from './local-formisch';

const FormSchema = v.object({
  serverName: v.pipe(
    v.string(),
    v.nonEmpty('This field is required.'),
    v.minLength(3, 'At least 3 characters.'),
  ),
  region: v.string('This field is required.'),
  containerImage: v.pipe(v.string(), v.nonEmpty('This field is required.')),
  serverType: v.string('This field is required.'),
  numOfInstances: v.number('This field is required.'),
  scalingThreshold: v.array(v.number()),
  storageType: v.picklist(['ssd', 'hdd']),
  restartOnFailure: v.boolean(),
  allowedNetworkProtocols: v.array(v.string()),
});

type FormValues = InferOutput<typeof FormSchema>;

function FormischForm() {
  const toastManager = useToastManager();

  const form = createForm({
    schema: FormSchema,
    initialInput: {
      serverName: '',
      region: null,
      containerImage: '',
      serverType: null,
      numOfInstances: null,
      scalingThreshold: [0.2, 0.8],
      storageType: 'ssd',
      restartOnFailure: true,
      allowedNetworkProtocols: [],
    },
  });

  function submitForm(data: FormValues) {
    toastManager.add({
      title: 'Form submitted',
      description: 'The form contains these values:',
      data,
    });
  }

  return (
    <Form aria-label="Launch new cloud server" onSubmit={handleSubmit(form, submitForm)}>
      <FormField of={form} path={['serverName']}>
        {(field) => (
          <Field.Root
            name={field.props.name}
            invalid={!field.isValid}
            touched={field.isTouched}
            dirty={field.isDirty}
          >
            <Field.Label>Server name</Field.Label>
            <Field.Control
              ref={field.props.ref}
              value={field.input ?? ''}
              onFocus={field.props.onFocus}
              onBlur={field.props.onBlur}
              onValueChange={field.onInput}
              placeholder="e.g. api-server-01"
            />
            <Field.Description>Must be 3 or more characters long</Field.Description>
            <Field.Error match={!!field.errors}>{field.errors?.[0]}</Field.Error>
          </Field.Root>
        )}
      </FormField>

      <FormField of={form} path={['region']}>
        {(field) => (
          <Field.Root
            name={field.props.name}
            invalid={!field.isValid}
            touched={field.isTouched}
            dirty={field.isDirty}
          >
            <Combobox.Root items={REGIONS} value={field.input} onValueChange={field.onInput}>
              <div class="relative text-sm leading-5 font-bold text-neutral-950 dark:text-white">
                <Field.Label class="mb-1 block">Region</Field.Label>
                <Combobox.InputGroup>
                  <Combobox.Input
                    placeholder="e.g. eu-central-1"
                    ref={field.props.ref}
                    onFocus={field.props.onFocus}
                    onBlur={field.props.onBlur}
                  />
                  <div class="absolute right-0 bottom-0 inline-flex h-full items-center justify-center text-neutral-500 dark:text-neutral-400">
                    <Combobox.Clear />
                    <Combobox.Trigger>
                      <Combobox.CaretDownIcon />
                    </Combobox.Trigger>
                  </div>
                </Combobox.InputGroup>
              </div>
              <Combobox.Portal>
                <Combobox.Positioner>
                  <Combobox.Popup>
                    <Combobox.Empty>No matches</Combobox.Empty>
                    <Combobox.List>
                      {(region: Accessor<string>) => {
                        return (
                          <Combobox.Item value={region()}>
                            <Combobox.ItemIndicator>
                              <CheckIcon />
                            </Combobox.ItemIndicator>
                            <span class="col-start-2">{region()}</span>
                          </Combobox.Item>
                        );
                      }}
                    </Combobox.List>
                  </Combobox.Popup>
                </Combobox.Positioner>
              </Combobox.Portal>
            </Combobox.Root>
            <Field.Error match={!!field.errors}>{field.errors?.[0]}</Field.Error>
          </Field.Root>
        )}
      </FormField>

      <FormField of={form} path={['containerImage']}>
        {(field) => (
          <Field.Root
            name={field.props.name}
            invalid={!field.isValid}
            touched={field.isTouched}
            dirty={field.isDirty}
          >
            <Autocomplete.Root
              items={IMAGES}
              mode="both"
              itemToStringValue={(itemValue: Image) => itemValue.url}
              value={field.input ?? ''}
              onValueChange={field.onInput}
            >
              <Field.Label>Container image</Field.Label>
              <Autocomplete.Input
                placeholder="e.g. docker.io/library/node:latest"
                ref={field.props.ref}
                onFocus={field.props.onFocus}
                onBlur={field.props.onBlur}
              />
              <Field.Description>Enter a registry URL with optional tags</Field.Description>
              <Autocomplete.Portal>
                <Autocomplete.Positioner>
                  <Autocomplete.Popup>
                    <Autocomplete.List>
                      {(image: Accessor<Image>) => {
                        return (
                          <Autocomplete.Item value={image()}>
                            <span>{image().name}</span>
                            <span class="font-mono whitespace-nowrap text-xs opacity-80">
                              {image().url}
                            </span>
                          </Autocomplete.Item>
                        );
                      }}
                    </Autocomplete.List>
                  </Autocomplete.Popup>
                </Autocomplete.Positioner>
              </Autocomplete.Portal>
            </Autocomplete.Root>
            <Field.Error match={!!field.errors}>{field.errors?.[0]}</Field.Error>
          </Field.Root>
        )}
      </FormField>

      <FormField of={form} path={['serverType']}>
        {(field) => (
          <Field.Root
            name={field.props.name}
            invalid={!field.isValid}
            touched={field.isTouched}
            dirty={field.isDirty}
          >
            <Select.Root
              items={SERVER_TYPES}
              value={field.input}
              onValueChange={field.onInput}
              inputRef={field.props.ref}
            >
              <div class="w-fit space-y-1">
                <Select.Label>Server type</Select.Label>
                <Select.Trigger
                  class="w-48"
                  onFocus={field.props.onFocus}
                  onBlur={field.props.onBlur}
                >
                  <Select.Value />
                  <Select.Icon>
                    <CaretUpDownIcon />
                  </Select.Icon>
                </Select.Trigger>
              </div>
              <Select.Portal>
                <Select.Positioner>
                  <Select.Popup>
                    <Select.ScrollUpArrow />
                    <Select.List>
                      <For each={SERVER_TYPES}>
                        {({ label, value: serverType }) => {
                          return (
                            <Select.Item value={serverType}>
                              <Select.ItemIndicator>
                                <CheckIcon />
                              </Select.ItemIndicator>
                              <Select.ItemText>{label}</Select.ItemText>
                            </Select.Item>
                          );
                        }}
                      </For>
                    </Select.List>
                    <Select.ScrollDownArrow />
                  </Select.Popup>
                </Select.Positioner>
              </Select.Portal>
            </Select.Root>
            <Field.Error match={!!field.errors}>{field.errors?.[0]}</Field.Error>
          </Field.Root>
        )}
      </FormField>

      <FormField of={form} path={['numOfInstances']}>
        {(field) => (
          <Field.Root
            name={field.props.name}
            invalid={!field.isValid}
            touched={field.isTouched}
            dirty={field.isDirty}
          >
            <NumberField.Root value={field.input} min={1} max={64} onValueChange={field.onInput}>
              <Field.Label>Number of instances</Field.Label>
              <NumberField.Group>
                <NumberField.Decrement>
                  <MinusIcon />
                </NumberField.Decrement>
                <NumberField.Input
                  ref={field.props.ref}
                  onFocus={field.props.onFocus}
                  onBlur={field.props.onBlur}
                />
                <NumberField.Increment>
                  <PlusIcon />
                </NumberField.Increment>
              </NumberField.Group>
            </NumberField.Root>
            <Field.Error match={!!field.errors}>{field.errors?.[0]}</Field.Error>
          </Field.Root>
        )}
      </FormField>

      <FormField of={form} path={['scalingThreshold']}>
        {(field) => (
          <Field.Root
            name={field.props.name}
            invalid={!field.isValid}
            touched={field.isTouched}
            dirty={field.isDirty}
          >
            <Fieldset.Root
              render={(renderProps) => (
                <Slider.Root
                  value={field.input}
                  onValueChange={field.onInput}
                  onValueCommitted={field.onInput}
                  thumbAlignment="edge"
                  min={0}
                  max={1}
                  step={0.01}
                  format={{
                    style: 'percent',
                    minimumFractionDigits: 0,
                    maximumFractionDigits: 0,
                  }}
                  class="w-full gap-y-2"
                  {...(renderProps as any)}
                />
              )}
            >
              <Fieldset.Legend>Scaling threshold</Fieldset.Legend>
              <Slider.Value class="col-start-2 text-end" />
              <Slider.Control>
                <Slider.Track>
                  <Slider.Indicator />
                  <Slider.Thumb
                    index={0}
                    aria-label="Minimum threshold"
                    onFocus={field.props.onFocus}
                    onBlur={field.props.onBlur}
                    inputRef={field.props.ref}
                  />
                  <Slider.Thumb
                    index={1}
                    aria-label="Maximum threshold"
                    onFocus={field.props.onFocus}
                    onBlur={field.props.onBlur}
                  />
                </Slider.Track>
              </Slider.Control>
            </Fieldset.Root>
          </Field.Root>
        )}
      </FormField>

      <FormField of={form} path={['storageType']}>
        {(field) => (
          <Field.Root
            name={field.props.name}
            invalid={!field.isValid}
            touched={field.isTouched}
            dirty={field.isDirty}
          >
            <Fieldset.Root
              render={(renderProps) => (
                <RadioGroup
                  class="gap-4"
                  value={field.input}
                  onValueChange={field.onInput}
                  inputRef={field.props.ref}
                  {...(renderProps as any)}
                />
              )}
            >
              <Fieldset.Legend class="-mt-px">Storage type</Fieldset.Legend>
              <Field.Item>
                <Field.Label>
                  <Radio.Root value="ssd" onFocus={field.props.onFocus} onBlur={field.props.onBlur}>
                    <Radio.Indicator />
                  </Radio.Root>
                  SSD
                </Field.Label>
              </Field.Item>
              <Field.Item>
                <Field.Label>
                  <Radio.Root value="hdd" onFocus={field.props.onFocus} onBlur={field.props.onBlur}>
                    <Radio.Indicator />
                  </Radio.Root>
                  HDD
                </Field.Label>
              </Field.Item>
            </Fieldset.Root>
          </Field.Root>
        )}
      </FormField>

      <FormField of={form} path={['restartOnFailure']}>
        {(field) => (
          <Field.Root
            name={field.props.name}
            invalid={!field.isValid}
            touched={field.isTouched}
            dirty={field.isDirty}
          >
            <Field.Label class="gap-2">
              Restart on failure
              <Switch.Root
                checked={field.input ?? false}
                inputRef={field.props.ref}
                onCheckedChange={field.onInput}
                onFocus={field.props.onFocus}
                onBlur={field.props.onBlur}
              >
                <Switch.Thumb />
              </Switch.Root>
            </Field.Label>
          </Field.Root>
        )}
      </FormField>

      <FormField of={form} path={['allowedNetworkProtocols']}>
        {(field) => (
          <Field.Root
            name={field.props.name}
            invalid={!field.isValid}
            touched={field.isTouched}
            dirty={field.isDirty}
          >
            <Fieldset.Root
              render={(renderProps) => (
                <CheckboxGroup
                  value={field.input}
                  onValueChange={field.onInput}
                  {...(renderProps as any)}
                />
              )}
            >
              <Fieldset.Legend class="mb-2">Allowed network protocols</Fieldset.Legend>
              <div class="flex gap-4">
                <For each={['http', 'https', 'ssh']}>
                  {(val) => {
                    return (
                      <Field.Item>
                        <Field.Label class="uppercase">
                          <Checkbox.Root
                            value={val}
                            inputRef={val === 'http' ? field.props.ref : undefined}
                            onFocus={field.props.onFocus}
                            onBlur={field.props.onBlur}
                          >
                            <Checkbox.Indicator>
                              <CheckIcon />
                            </Checkbox.Indicator>
                          </Checkbox.Root>
                          {val}
                        </Field.Label>
                      </Field.Item>
                    );
                  }}
                </For>
              </div>
            </Fieldset.Root>
          </Field.Root>
        )}
      </FormField>

      <Button type="submit" class="mt-3">
        Launch server
      </Button>
    </Form>
  );
}

export default function App() {
  return (
    <ToastProvider>
      <FormischForm />
    </ToastProvider>
  );
}

function CaretUpDownIcon(props: JSX.IntrinsicElements['svg']) {
  return (
    <svg
      width="16"
      height="16"
      viewBox="0 0 16 16"
      fill="currentColor"
      {...props}
      style={props.style}
    >
      <path d="M11 10H5l3 3.5zm0-4H5l3-3.5z" />
    </svg>
  );
}

function CheckIcon(props: JSX.IntrinsicElements['svg']) {
  return (
    <svg
      width="16"
      height="16"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      {...props}
      style={props.style}
    >
      <path d="m2.5 8.5 4 4 7-9" />
    </svg>
  );
}

function PlusIcon(props: JSX.IntrinsicElements['svg']) {
  return (
    <svg
      width="16"
      height="16"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      stroke-linecap="square"
      stroke-linejoin="round"
      {...props}
      style={props.style}
    >
      <path d="M1.5 8h13M8 14.5v-13" />
    </svg>
  );
}

function MinusIcon(props: JSX.IntrinsicElements['svg']) {
  return (
    <svg
      width="16"
      height="16"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      stroke-linecap="square"
      stroke-linejoin="round"
      {...props}
      style={props.style}
    >
      <path d="M1.5 8h13" />
    </svg>
  );
}

function cartesian<T extends string[][]>(...arrays: T): string[][] {
  return arrays.reduce<string[][]>(
    (acc, curr) => acc.flatMap((a) => curr.map((b) => [...a, b])),
    [[]],
  );
}

const REGIONS = cartesian(['us', 'eu', 'ap'], ['central', 'east', 'west'], ['1', '2', '3']).map(
  (part) => part.join('-'),
);

interface Image {
  url: string;
  name: string;
}
/* prettier-ignore */
const IMAGES: Image[] = ['nginx:1.29-alpine', 'node:22-slim', 'postgres:18', 'redis:8.2.2-alpine'].map((name) => ({
  url: `docker.io/library/${name}`,
  name,
}));

const SERVER_TYPES = [
  { label: 'Select server type', value: null },
  ...cartesian(['t', 'm'], ['1', '2'], ['small', 'medium', 'large']).map((part) => {
    const value = part.join('.').replace('.', '');
    return { label: value, value };
  }),
];

Initialize the form

Describe the values with a Valibot schema and create a form store with the initial input.

Initialize a form store
import { createForm } from '@formisch/solid';
import * as v from 'valibot';

const AccountSchema = v.object({
  username: v.pipe(v.string(), v.nonEmpty('This field is required.')),
  email: v.pipe(v.string(), v.email('Enter a valid email.')),
});

const form = createForm({
  schema: AccountSchema,
  initialInput: { username: '', email: '' },
});

Integrate components

Use <Field> to connect each control. Its render function receives a reactive field store: read it in JSX and don’t destructure it. Base UI controls aren’t native inputs that field.props can be spread on, so pass field.input as the value and field.onInput as the change handler, and forward ref and the focus handlers so the field can be focused and marked as touched.

Integrating a field with Base UI components
import { Field as FormField } from '@formisch/solid';
import { Field } from 'base-ui-solid/field';

<FormField of={form} path={['username']}>
  {(field) => (
    <Field.Root
      name={field.props.name}
      invalid={!field.isValid}
      touched={field.isTouched}
      dirty={field.isDirty}
    >
      <Field.Label>Username</Field.Label>
      <Field.Control
        value={field.input ?? ''}
        onValueChange={field.onInput}
        ref={field.props.ref}
        onFocus={field.props.onFocus}
        onBlur={field.props.onBlur}
      />
      <Field.Error match={!!field.errors}>{field.errors?.[0]}</Field.Error>
    </Field.Root>
  )}
</FormField>;

Field validation

Validation rules live in the schema. By default, the form validates when it’s submitted and revalidates a field on input afterwards. Use the validate and revalidate options of createForm to change when validation runs.

Defining validation rules
const AccountSchema = v.object({
  username: v.pipe(v.string(), v.nonEmpty('This field is required.'), v.minLength(2, 'Too short.')),
});

Submitting data

Pass the handler to handleSubmit to validate the form before receiving its output.

Form submission handler
import { handleSubmit } from '@formisch/solid';
import { Form } from 'base-ui-solid/form';

<Form
  onSubmit={handleSubmit(form, async (output) => {
    await fetch('/api/account', { method: 'POST', body: JSON.stringify(output) });
  })}
/>;

TanStack Form

TanStack Form’s Solid adapter (@tanstack/solid-form) doesn’t support Solid 2.0 yet. The demo below uses a small local helper (included in its source) that mirrors TanStack Form’s field API and validation flow, so it can be swapped for the adapter once it does.

Must be 3 or more characters long

Enter a registry URL with optional tags

Server type
Scaling threshold
20% – 80%
Storage type
Allowed network protocols
import { For } from 'solid-js';
import type { Accessor } from 'solid-js';
// Solid controller preserves this example's field API and validation flow.
import type { JSX } from '@solidjs/web';
import { createControlledForm } from './solid-controller';
import { Button } from './button';
import { CheckboxGroup } from './checkbox-group';
import { RadioGroup } from './radio-group';
import { ToastProvider, useToastManager } from './toast';
import * as Autocomplete from './autocomplete';
import * as Checkbox from './checkbox';
import * as Combobox from './combobox';
import * as Field from './field';
import * as Fieldset from './fieldset';
import * as NumberField from './number-field';
import * as Radio from './radio';
import * as Select from './select';
import * as Slider from './slider';
import * as Switch from './switch';

type DeepKeys<T> = keyof T;
type ValidationError = string;

interface FormValues {
  serverName: string;
  region: string | null;
  containerImage: string;
  serverType: string | null;
  numOfInstances: number | null;
  scalingThreshold: number[];
  storageType: 'ssd' | 'hdd';
  restartOnFailure: boolean;
  allowedNetworkProtocols: string[];
}

const defaultValues: FormValues = {
  serverName: '',
  region: null,
  containerImage: '',
  serverType: null,
  numOfInstances: null,
  scalingThreshold: [0.2, 0.8],
  storageType: 'ssd',
  restartOnFailure: true,
  allowedNetworkProtocols: [],
};

function TanstackForm() {
  const toastManager = useToastManager();

  const form = createControlledForm({
    defaultValues,
    onSubmit: ({ value: formValues }) => {
      toastManager.add({
        title: 'Form submitted',
        description: 'The form contains these values:',
        data: formValues,
      });
    },
    validators: {
      onDynamic: ({ value: formValues }) => {
        const errors: Partial<Record<DeepKeys<FormValues>, ValidationError>> = {};

        (
          ['serverName', 'region', 'containerImage', 'serverType', 'numOfInstances'] as const
        ).forEach((requiredField) => {
          if (!formValues[requiredField]) {
            errors[requiredField] = 'This is a required field.';
          }
        });

        if (formValues.serverName && formValues.serverName.length < 3) {
          errors.serverName = 'At least 3 characters.';
        }

        return isEmpty(errors) ? undefined : { form: errors, fields: errors };
      },
    },
  });

  return (
    <form
      aria-label="Launch new cloud server"
      class="flex w-full max-w-3xs flex-col gap-5 sm:max-w-[20rem]"
      novalidate
      onSubmit={(event) => {
        event.preventDefault();
        form.handleSubmitForm();
      }}
    >
      <form.Field
        name="serverName"
        children={(field) => {
          return (
            <Field.Root
              name={field.name}
              invalid={!field.state.meta.isValid}
              dirty={field.state.meta.isDirty}
              touched={field.state.meta.isTouched}
            >
              <Field.Label>Server name</Field.Label>
              <Field.Control
                value={field.state.value}
                onValueChange={field.handleChange}
                onFocusOut={field.handleBlur}
                placeholder="e.g. api-server-01"
              />
              <Field.Description>Must be 3 or more characters long</Field.Description>
              <Field.Error match={!field.state.meta.isValid}>
                {field.state.meta.errors.join(',')}
              </Field.Error>
            </Field.Root>
          );
        }}
      />

      <form.Field
        name="region"
        children={(field) => {
          return (
            <Field.Root
              name={field.name}
              invalid={!field.state.meta.isValid}
              dirty={field.state.meta.isDirty}
              touched={field.state.meta.isTouched}
            >
              <Combobox.Root
                items={REGIONS}
                value={field.state.value}
                onValueChange={field.handleChange}
              >
                <div class="relative text-sm leading-5 font-bold text-neutral-950 dark:text-white">
                  <Field.Label class="mb-1 block">Region</Field.Label>
                  <Combobox.InputGroup>
                    <Combobox.Input placeholder="e.g. eu-central-1" onFocusOut={field.handleBlur} />
                    <div class="absolute right-0 bottom-0 inline-flex h-full items-center justify-center text-neutral-500 dark:text-neutral-400">
                      <Combobox.Clear />
                      <Combobox.Trigger>
                        <Combobox.CaretDownIcon />
                      </Combobox.Trigger>
                    </div>
                  </Combobox.InputGroup>
                </div>
                <Combobox.Portal>
                  <Combobox.Positioner>
                    <Combobox.Popup>
                      <Combobox.Empty>No matches</Combobox.Empty>
                      <Combobox.List>
                        {(region: Accessor<string>) => {
                          return (
                            <Combobox.Item value={region()}>
                              <Combobox.ItemIndicator>
                                <CheckIcon />
                              </Combobox.ItemIndicator>
                              <span class="col-start-2">{region()}</span>
                            </Combobox.Item>
                          );
                        }}
                      </Combobox.List>
                    </Combobox.Popup>
                  </Combobox.Positioner>
                </Combobox.Portal>
              </Combobox.Root>

              <Field.Error match={!field.state.meta.isValid}>
                {field.state.meta.errors.join(',')}
              </Field.Error>
            </Field.Root>
          );
        }}
      />

      <form.Field
        name="containerImage"
        children={(field) => {
          return (
            <Field.Root
              name={field.name}
              invalid={!field.state.meta.isValid}
              dirty={field.state.meta.isDirty}
              touched={field.state.meta.isTouched}
            >
              <Autocomplete.Root
                items={IMAGES}
                mode="both"
                value={field.state.value}
                onValueChange={field.handleChange}
                itemToStringValue={(itemValue: Image) => itemValue.url}
              >
                <Field.Label>Container image</Field.Label>
                <Autocomplete.Input
                  placeholder="e.g. docker.io/library/node:latest"
                  onFocusOut={field.handleBlur}
                />
                <Field.Description>Enter a registry URL with optional tags</Field.Description>
                <Autocomplete.Portal>
                  <Autocomplete.Positioner>
                    <Autocomplete.Popup>
                      <Autocomplete.List>
                        {(image: Accessor<Image>) => {
                          return (
                            <Autocomplete.Item value={image()}>
                              <span>{image().name}</span>
                              <span class="font-mono whitespace-nowrap text-xs opacity-80">
                                {image().url}
                              </span>
                            </Autocomplete.Item>
                          );
                        }}
                      </Autocomplete.List>
                    </Autocomplete.Popup>
                  </Autocomplete.Positioner>
                </Autocomplete.Portal>
              </Autocomplete.Root>
              <Field.Error match={!field.state.meta.isValid}>
                {field.state.meta.errors.join(',')}
              </Field.Error>
            </Field.Root>
          );
        }}
      />

      <form.Field
        name="serverType"
        children={(field) => {
          return (
            <Field.Root
              name={field.name}
              invalid={!field.state.meta.isValid}
              dirty={field.state.meta.isDirty}
              touched={field.state.meta.isTouched}
            >
              <Select.Root
                items={SERVER_TYPES}
                value={field.state.value}
                onValueChange={field.handleChange}
              >
                <div class="w-fit space-y-1">
                  <Select.Label>Server type</Select.Label>
                  <Select.Trigger class="w-48" onFocusOut={field.handleBlur}>
                    <Select.Value />
                    <Select.Icon>
                      <CaretUpDownIcon />
                    </Select.Icon>
                  </Select.Trigger>
                </div>
                <Select.Portal>
                  <Select.Positioner>
                    <Select.Popup>
                      <Select.ScrollUpArrow />
                      <Select.List>
                        <For each={SERVER_TYPES}>
                          {({ label, value }) => {
                            return (
                              <Select.Item value={value}>
                                <Select.ItemIndicator>
                                  <CheckIcon />
                                </Select.ItemIndicator>
                                <Select.ItemText>{label}</Select.ItemText>
                              </Select.Item>
                            );
                          }}
                        </For>
                      </Select.List>
                      <Select.ScrollDownArrow />
                    </Select.Popup>
                  </Select.Positioner>
                </Select.Portal>
              </Select.Root>
              <Field.Error match={!field.state.meta.isValid}>
                {field.state.meta.errors.join(',')}
              </Field.Error>
            </Field.Root>
          );
        }}
      />

      <form.Field
        name="numOfInstances"
        children={(field) => {
          return (
            <Field.Root
              name={field.name}
              invalid={!field.state.meta.isValid}
              dirty={field.state.meta.isDirty}
              touched={field.state.meta.isTouched}
            >
              <NumberField.Root
                value={field.state.value}
                onValueChange={field.handleChange}
                min={1}
                max={64}
              >
                <Field.Label>Number of instances</Field.Label>
                <NumberField.Group>
                  <NumberField.Decrement>
                    <MinusIcon />
                  </NumberField.Decrement>
                  <NumberField.Input onFocusOut={field.handleBlur} />
                  <NumberField.Increment>
                    <PlusIcon />
                  </NumberField.Increment>
                </NumberField.Group>
              </NumberField.Root>
              <Field.Error match={!field.state.meta.isValid}>
                {field.state.meta.errors.join(',')}
              </Field.Error>
            </Field.Root>
          );
        }}
      />

      <form.Field
        name="scalingThreshold"
        children={(field) => {
          return (
            <Field.Root
              name={field.name}
              invalid={!field.state.meta.isValid}
              dirty={field.state.meta.isDirty}
              touched={field.state.meta.isTouched}
            >
              <Fieldset.Root
                render={(renderProps) => (
                  <Slider.Root
                    value={field.state.value}
                    onValueChange={field.handleChange}
                    onValueCommitted={field.handleChange}
                    thumbAlignment="edge"
                    min={0}
                    max={1}
                    step={0.01}
                    format={{
                      style: 'percent',
                      minimumFractionDigits: 0,
                      maximumFractionDigits: 0,
                    }}
                    class="w-full gap-y-2"
                    {...(renderProps as any)}
                  />
                )}
              >
                <Fieldset.Legend>Scaling threshold</Fieldset.Legend>
                <Slider.Value class="col-start-2 text-end" />
                <Slider.Control>
                  <Slider.Track>
                    <Slider.Indicator />
                    <Slider.Thumb
                      index={0}
                      aria-label="Minimum threshold"
                      onFocusOut={field.handleBlur}
                    />
                    <Slider.Thumb
                      index={1}
                      aria-label="Maximum threshold"
                      onFocusOut={field.handleBlur}
                    />
                  </Slider.Track>
                </Slider.Control>
              </Fieldset.Root>
              <Field.Error match={!field.state.meta.isValid}>
                {field.state.meta.errors.join(',')}
              </Field.Error>
            </Field.Root>
          );
        }}
      />

      <form.Field
        name="storageType"
        children={(field) => {
          return (
            <Field.Root
              name={field.name}
              invalid={!field.state.meta.isValid}
              dirty={field.state.meta.isDirty}
              touched={field.state.meta.isTouched}
            >
              <Fieldset.Root
                render={(renderProps) => (
                  <RadioGroup
                    value={field.state.value}
                    onValueChange={field.handleChange}
                    class="gap-4"
                    {...(renderProps as any)}
                  />
                )}
              >
                <Fieldset.Legend class="-mt-px">Storage type</Fieldset.Legend>
                <For each={['ssd', 'hdd']}>
                  {(radioValue) => (
                    <Field.Item>
                      <Field.Label class="uppercase">
                        <Radio.Root value={radioValue}>
                          <Radio.Indicator />
                        </Radio.Root>
                        {radioValue}
                      </Field.Label>
                    </Field.Item>
                  )}
                </For>
              </Fieldset.Root>
              <Field.Error match={!field.state.meta.isValid}>
                {field.state.meta.errors.join(',')}
              </Field.Error>
            </Field.Root>
          );
        }}
      />

      <form.Field
        name="restartOnFailure"
        children={(field) => {
          return (
            <Field.Root
              name={field.name}
              invalid={!field.state.meta.isValid}
              dirty={field.state.meta.isDirty}
              touched={field.state.meta.isTouched}
            >
              <Field.Label class="gap-2">
                Restart on failure
                <Switch.Root
                  checked={field.state.value}
                  onCheckedChange={field.handleChange}
                  onFocusOut={field.handleBlur}
                >
                  <Switch.Thumb />
                </Switch.Root>
              </Field.Label>
              <Field.Error match={!field.state.meta.isValid}>
                {field.state.meta.errors.join(',')}
              </Field.Error>
            </Field.Root>
          );
        }}
      />

      <form.Field
        name="allowedNetworkProtocols"
        children={(field) => {
          return (
            <Field.Root
              name={field.name}
              invalid={!field.state.meta.isValid}
              dirty={field.state.meta.isDirty}
              touched={field.state.meta.isTouched}
            >
              <Fieldset.Root
                render={(renderProps) => (
                  <CheckboxGroup
                    value={field.state.value}
                    onValueChange={field.handleChange}
                    {...(renderProps as any)}
                  />
                )}
              >
                <Fieldset.Legend class="mb-2">Allowed network protocols</Fieldset.Legend>
                <div class="flex gap-4">
                  <For each={['http', 'https', 'ssh']}>
                    {(checkboxValue) => {
                      return (
                        <Field.Item>
                          <Field.Label class="uppercase">
                            <Checkbox.Root value={checkboxValue} onFocusOut={field.handleBlur}>
                              <Checkbox.Indicator>
                                <CheckIcon />
                              </Checkbox.Indicator>
                            </Checkbox.Root>
                            {checkboxValue}
                          </Field.Label>
                        </Field.Item>
                      );
                    }}
                  </For>
                </div>
              </Fieldset.Root>
              <Field.Error match={!field.state.meta.isValid}>
                {field.state.meta.errors.join(',')}
              </Field.Error>
            </Field.Root>
          );
        }}
      />

      <Button type="submit" class="mt-3">
        Launch server
      </Button>
    </form>
  );
}

export default function App() {
  return (
    <ToastProvider>
      <TanstackForm />
    </ToastProvider>
  );
}

function CaretUpDownIcon(props: JSX.IntrinsicElements['svg']) {
  return (
    <svg
      width="16"
      height="16"
      viewBox="0 0 16 16"
      fill="currentColor"
      {...props}
      style={props.style}
    >
      <path d="M11 10H5l3 3.5zm0-4H5l3-3.5z" />
    </svg>
  );
}

function CheckIcon(props: JSX.IntrinsicElements['svg']) {
  return (
    <svg
      width="16"
      height="16"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      {...props}
      style={props.style}
    >
      <path d="m2.5 8.5 4 4 7-9" />
    </svg>
  );
}

function PlusIcon(props: JSX.IntrinsicElements['svg']) {
  return (
    <svg
      width="16"
      height="16"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      stroke-linecap="square"
      stroke-linejoin="round"
      {...props}
      style={props.style}
    >
      <path d="M1.5 8h13M8 14.5v-13" />
    </svg>
  );
}

function MinusIcon(props: JSX.IntrinsicElements['svg']) {
  return (
    <svg
      width="16"
      height="16"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      stroke-linecap="square"
      stroke-linejoin="round"
      {...props}
      style={props.style}
    >
      <path d="M1.5 8h13" />
    </svg>
  );
}

function isEmpty(object: Partial<Record<DeepKeys<FormValues>, ValidationError>>) {
  // eslint-disable-next-line
  for (const _ in object) {
    return false;
  }
  return true;
}

function cartesian<T extends string[][]>(...arrays: T): string[][] {
  return arrays.reduce<string[][]>(
    (acc, curr) => acc.flatMap((a) => curr.map((b) => [...a, b])),
    [[]],
  );
}

const REGIONS = cartesian(['us', 'eu', 'ap'], ['central', 'east', 'west'], ['1', '2', '3']).map(
  (part) => part.join('-'),
);

interface Image {
  url: string;
  name: string;
}
/* prettier-ignore */
const IMAGES: Image[] = ['nginx:1.29-alpine', 'node:22-slim', 'postgres:18', 'redis:8.2.2-alpine'].map((name) => ({
  url: `docker.io/library/${name}`,
  name,
}));

const SERVER_TYPES = [
  { label: 'Select server type', value: null },
  ...cartesian(['t', 'm'], ['1', '2'], ['small', 'medium', 'large']).map((part) => {
    const value = part.join('.').replace('.', '');
    return { label: value, value };
  }),
];

Initialize the form

Create a form instance with initial values and a submission callback. This example retains the upstream field API through the local Solid controller.

Initialize a form instance
import { createControlledForm } from './solid-controller';

const form = createControlledForm({
  defaultValues: { username: '', email: '' },
  onSubmit: async ({ value }) => {
    await fetch('/api/account', { method: 'POST', body: JSON.stringify(value) });
  },
});

Integrate components

Use <form.Field> to connect each control. Read its reactive state in JSX and forward the change and focus-out handlers.

Integrating form fields with Base UI components
import { Field } from 'base-ui-solid/field';

<form.Field name="username">
  {(field) => (
    <Field.Root
      name={field.name}
      invalid={!field.state.meta.isValid}
      dirty={field.state.meta.isDirty}
      touched={field.state.meta.isTouched}
    >
      <Field.Label>Username</Field.Label>
      <Field.Control
        value={field.state.value}
        onValueChange={field.handleChange}
        onFocusOut={field.handleBlur}
      />
      <Field.Error match={!field.state.meta.isValid}>
        {field.state.meta.errors.join(', ')}
      </Field.Error>
    </Field.Root>
  )}
</form.Field>;

Form validation

Return field errors from the form-level validator. After the first submit attempt, changes revalidate the form.

Form-level validators
const form = createControlledForm({
  defaultValues: { username: '', email: '' },
  validators: {
    onDynamic: ({ value }) => ({
      fields: {
        ...(!value.username ? { username: 'This field is required.' } : {}),
        ...(!value.email.includes('@') ? { email: 'Enter a valid email.' } : {}),
      },
    }),
  },
});

Field validation

The local controller supports synchronous validation. For asynchronous checks, use Base UI’s validate prop and validationDebounceTime as described in Custom validation.

Text input using custom asynchronous validation
<Field.Root
  name="username"
  validationMode="onChange"
  validationDebounceTime={300}
  validate={async (value) => {
    const response = await fetch(`/api/username?value=${encodeURIComponent(String(value))}`);
    const result = await response.json();
    return result.available ? null : 'This username is not available.';
  }}
>
  <Field.Control />
  <Field.Error />
</Field.Root>

Submitting data

Prevent the native navigation and call the form’s submission method. The controller validates before invoking onSubmit.

Form submission handler
<form
  onSubmit={(event) => {
    event.preventDefault();
    form.handleSubmitForm();
  }}
>
  <button type="submit">Submit</button>
</form>