# Overview

TanStack Form is the ultimate solution for handling forms in web applications, providing a powerful and flexible approach to form management. Designed with first-class TypeScript support, headless UI components, and a framework-agnostic design, it streamlines form handling and ensures a seamless experience across various front-end frameworks.

## Motivation

Most web frameworks do not offer a comprehensive solution for form handling, leaving developers to create their own custom implementations or rely on less-capable libraries. This often results in a lack of consistency, poor performance, and increased development time. TanStack Form aims to address these challenges by providing an all-in-one solution for managing forms that is both powerful and easy to use.

With TanStack Form, developers can tackle common form-related challenges such as:

- Reactive data binding and state management
- Complex validation and error handling
- Accessibility and responsive design
- Internationalization and localization
- Cross-platform compatibility and custom styling

By providing a complete solution for these challenges, TanStack Form empowers developers to build robust and user-friendly forms with ease.

## Enough talk, show me some code already!

In the example below, you can see TanStack Form in action with the Vue framework adapter:

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

```vue file="App.vue"
<script setup lang="ts">
import { useForm } from '@tanstack/vue-form'
import FieldInfo from './FieldInfo.vue'
import TextInput from './TextInput.vue'

const form = useForm({
  defaultValues: {
    firstName: '',
    lastName: '',
  },
  onSubmit: async ({ value }) => {
    // Do something with the validated form values
    console.log(value)
  },
})

function handleSubmit() {
  // Validate the form before calling onSubmit.
  void form.handleSubmit().catch(console.error)
}
</script>

<template>
  <form @submit.prevent="handleSubmit">
    <!-- A type-safe field component -->
    <form.Field
      name="firstName"
      :validators="[
        {
          // Validate on change as well as on submit.
          triggers: ['change'],
          run: ({ value }) => {
            if (value.trim().length === 0) {
              return 'Enter your first name'
            }
            return undefined
          },
        },
      ]"
      v-slot="{ field }"
    >
      <div>
        <!-- Use your own markup and UI libraries! -->
        <label :for="field.name">First name</label>
        <TextInput :field="field" />
        <FieldInfo :field="field" />
      </div>
    </form.Field>

    <form.Field name="lastName" v-slot="{ field }">
      <div>
        <label :for="field.name">Last name</label>
        <TextInput :field="field" />
        <FieldInfo :field="field" />
      </div>
    </form.Field>

    <!-- Re-render this button when the selected state changes. -->
    <form.Subscribe
      :selector="(state) => [state.canSubmit, state.isSubmitting] as const"
      v-slot="[canSubmit, isSubmitting]"
    >
      <button type="submit" :disabled="!canSubmit">
        {{ isSubmitting ? 'Submitting...' : 'Submit' }}
      </button>
    </form.Subscribe>
    <!-- Restore default values and clear validation and interaction state. -->
    <button type="reset" @click.prevent="form.reset()">Reset</button>
  </form>
</template>
```

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

// This file provides the UI. Use any UI library you prefer.
defineProps<{ field: FieldWithValue<string> }>()
</script>

<template>
  <input
    :id="field.name"
    :name="field.name"
    :value="field.value"
    @input="field.handleChange(($event.target as HTMLInputElement).value)"
    @blur="field.handleBlur"
  />
</template>
```

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

// This file provides the UI. Use any UI library you prefer.
defineProps<{ field: AnyFieldApi }>()
</script>

<template>
  <p v-if="!field.meta.isValid" role="alert">
    {{ field.errors.map((error) => error.message).join(', ') }}
  </p>
</template>
```

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

## Next steps

Use [Installation](./installation) to set up your framework package. The
[Form API](./reference/interfaces/FormApi) and
[Field API](./reference/interfaces/FieldApi) references describe the methods and
state available as you extend your form.
