# 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.

Svelte's `SvelteFormType` 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/svelte-form'
import type { SvelteFormType } from '@tanstack/svelte-form'

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

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

```svelte file="AddressFields.svelte"
<script lang="ts">
  import type { ProfileForm } from './shared-form.js'

  const { form }: { form: ProfileForm } = $props()
</script>

<form.Field name="address.street">
  {#snippet children(field)}
    <input
      aria-label="Street"
      value={field.value}
      oninput={(event) => field.handleChange(event.currentTarget.value)}
    />
  {/snippet}
</form.Field>
<form.Field name="address.city">
  {#snippet children(field)}
    <input
      aria-label="City"
      value={field.value}
      oninput={(event) => field.handleChange(event.currentTarget.value)}
    />
  {/snippet}
</form.Field>
```

```svelte file="ProfileForm.svelte"
<script lang="ts">
  import { createForm } from '@tanstack/svelte-form'
  import AddressFields from './AddressFields.svelte'
  import { profileFormOptions } from './shared-form.js'

  const form = createForm(() => ({
    ...profileFormOptions,
    onSubmit: ({ value }) => console.log(value),
  }))
</script>

<AddressFields {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.

Type the Svelte component's field prop as `FieldWithValue<string>`, then pass it
the field from the `form.Field` snippet.

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

```svelte file="TextField.svelte"
<script lang="ts">
  import type { FieldWithValue } from '@tanstack/svelte-form'

  interface Props {
    field: FieldWithValue<string>
    label: string
  }

  const { field, label }: Props = $props()
</script>

<label>
  <span>{label}</span>
  <input
    name={field.name}
    value={field.value}
    onblur={field.handleBlur}
    oninput={(event) => field.handleChange(event.currentTarget.value)}
  />
</label>
```

```svelte file="NameField.svelte"
<script lang="ts">
  import TextField from './TextField.svelte'
  import type { ProfileForm } from './shared-form.js'

  const { form }: { form: ProfileForm } = $props()
</script>

<form.Field name="name">
  {#snippet children(field)}
    <TextField {field} label="Name" />
  {/snippet}
</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.

Svelte provides `AnySvelteFormApi` for form-level components. Pass the field
from the `form.Field` snippet to `FieldErrors`, and pass the form instance to
`SubmitButton`.

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

```svelte file="FieldErrors.svelte"
<script lang="ts">
  import type { AnyFieldApi } from '@tanstack/svelte-form'

  const { field }: { field: AnyFieldApi } = $props()
</script>

<small role="alert" aria-live="polite">
  {field.errors.map((error) => error.message).join(', ')}
</small>
```

```svelte file="SubmitButton.svelte"
<script lang="ts">
  import type { AnySvelteFormApi } from '@tanstack/svelte-form'

  const { form }: { form: AnySvelteFormApi } = $props()
</script>

<form.Subscribe
  selector={(state) => [state.canSubmit, state.isSubmitting] as const}
>
  {#snippet children([canSubmit, isSubmitting])}
    <button type="submit" disabled={!canSubmit || isSubmitting}>
      {isSubmitting ? 'Submitting...' : 'Submit'}
    </button>
  {/snippet}
</form.Subscribe>
```

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