# Content temporarily unavailable
As a form grows, keeping every field in one component can make the code harder
to navigate and maintain. You can move related fields into smaller components
while keeping one form instance, but each new component boundary needs a type
for the form or field it receives.

## Split a large form into sections

First define the form's reusable options with `formOptions`. In this example,
the same module also exports a named form type derived from those options. The
parent can add page-specific options, such as `onSubmit`, when it creates the
form, while extracted sections can import the same form type.

Solid's `SolidFormType` derives the form prop from the shared options. The
result keeps the field names and values available to `form.Field` in the
extracted component.

<!-- ::start:tabs variant="files" -->

```ts file="shared-form.ts"
import { formOptions } from '@tanstack/solid-form'
import type { SolidFormType } from '@tanstack/solid-form'

export const profileFormOptions = formOptions({
  defaultValues: {
    name: '',
    address: {
      street: '',
      city: '',
    },
  },
})

export type ProfileForm = SolidFormType<typeof profileFormOptions>
```

```tsx file="AddressFields.tsx"
import type { ProfileForm } from './shared-form'

interface AddressFieldsProps {
  form: ProfileForm
}

export function AddressFields(props: AddressFieldsProps) {
  return (
    <>
      <props.form.Field name="address.street">
        {(field) => (
          <input
            aria-label="Street"
            value={field().value}
            onInput={(event) => field().handleChange(event.currentTarget.value)}
          />
        )}
      </props.form.Field>
      <props.form.Field name="address.city">
        {(field) => (
          <input
            aria-label="City"
            value={field().value}
            onInput={(event) => field().handleChange(event.currentTarget.value)}
          />
        )}
      </props.form.Field>
    </>
  )
}
```

```tsx file="ProfileForm.tsx"
import { createForm } from '@tanstack/solid-form'
import { AddressFields } from './AddressFields'
import { profileFormOptions } from './shared-form'

export function ProfileForm() {
  const form = createForm(() => ({
    ...profileFormOptions,
    onSubmit: ({ value }) => console.log(value),
  }))

  return <AddressFields form={form} />
}
```

<!-- ::end:tabs -->

## Extract a field component by value type

After splitting the form into sections, you may still have repeated controls
for values such as strings, numbers, or dates. These controls don't need to
know the form's complete data shape or the path of a particular field. They
only need the type of the value they read and update.

`FieldWithValue<T>` describes a field by the value type a reusable component
handles. This preserves type checking when the component reads or updates the
value without tying it to a particular field path or form shape.

Solid's field render prop is an accessor, so the component accepts an
`Accessor<FieldWithValue<string>>`.

<!-- ::start:tabs variant="files" -->

```tsx file="TextField.tsx"
import type { Accessor } from 'solid-js'
import type { FieldWithValue } from '@tanstack/solid-form'

interface TextFieldProps {
  field: Accessor<FieldWithValue<string>>
  label: string
}

export function TextField(props: TextFieldProps) {
  return (
    <label>
      <span>{props.label}</span>
      <input
        name={props.field().name}
        value={props.field().value}
        onBlur={props.field().handleBlur}
        onInput={(event) =>
          props.field().handleChange(event.currentTarget.value)
        }
      />
    </label>
  )
}
```

```tsx file="NameField.tsx"
import { TextField } from './TextField'
import type { ProfileForm } from './shared-form'

export function NameField(props: { form: ProfileForm }) {
  return (
    <props.form.Field name="name">
      {(field) => <TextField field={field} label="Name" />}
    </props.form.Field>
  )
}
```

<!-- ::end:tabs -->

## Accept any form or field

Some extracted controls behave the same regardless of the form's data. An
error display only needs field metadata, while a submit or reset button may
only need form state and methods. Giving these controls the concrete
`ProfileForm` type would couple them to details they don't use.

Use `AnyFieldApi` when a control doesn't depend on the field's value type. For
form-level controls, use the adapter's `Any*FormApi` type. These types
deliberately remove information about values and field paths, so use a concrete
type when a component reads either one.

Solid provides `AnySolidFormApi` for form-level components. Its field render
prop remains an accessor, so `FieldErrors` accepts an
`Accessor<AnyFieldApi>`.

<!-- ::start:tabs variant="files" -->

```tsx file="FieldErrors.tsx"
import type { Accessor } from 'solid-js'
import type { AnyFieldApi } from '@tanstack/solid-form'

export function FieldErrors(props: { field: Accessor<AnyFieldApi> }) {
  return (
    <small role="alert" aria-live="polite">
      {props
        .field()
        .errors.map((error) => error.message)
        .join(', ')}
    </small>
  )
}
```

```tsx file="SubmitButton.tsx"
import type { AnySolidFormApi } from '@tanstack/solid-form'

export function SubmitButton(props: { form: AnySolidFormApi }) {
  return (
    <props.form.Subscribe
      selector={(state) => [state.canSubmit, state.isSubmitting] as const}
    >
      {(state) => (
        <button type="submit" disabled={!state()[0] || state()[1]}>
          {state()[1] ? 'Submitting...' : 'Submit'}
        </button>
      )}
    </props.form.Subscribe>
  )
}
```

<!-- ::end:tabs -->
