# Input OTP: With Field

> Inside a `<Field />` the label, description and error are linked for you. Enter anything but 000000 to see the error.

Example: https://hextaui.com/docs/input-otp/examples/field
Component docs: https://hextaui.com/docs/input-otp.md

## Add this example

```bash
npx shadcn@latest add https://hextaui.com/r/input-otp-field.json
```

This adds `components/examples/input-otp/field.tsx` with the Input OTP component and the HextaUI theme tokens.

## Source

```tsx title="components/examples/input-otp/field.tsx"
"use client"

import * as React from "react"

import {
  Field,
  FieldDescription,
  FieldError,
  FieldLabel,
} from "@/components/ui/field"
import {
  InputOTP,
  InputOTPGroup,
  InputOTPSeparator,
  InputOTPSlot,
} from "@/components/ui/input-otp"

export function InputOTPField() {
  const [value, setValue] = React.useState("")
  const [error, setError] = React.useState<string>()

  return (
    <Field invalid={error !== undefined} className="w-fit">
      <FieldLabel>Verification code</FieldLabel>
      <InputOTP
        length={6}
        value={value}
        onValueChange={(next) => {
          setValue(next)
          setError(undefined)
        }}
        onValueComplete={(code) => {
          if (code !== "000000") {
            setError("That code has expired. Request a new one.")
          }
        }}
      >
        <InputOTPGroup>
          <InputOTPSlot />
          <InputOTPSlot />
          <InputOTPSlot />
        </InputOTPGroup>
        <InputOTPSeparator />
        <InputOTPGroup>
          <InputOTPSlot />
          <InputOTPSlot />
          <InputOTPSlot />
        </InputOTPGroup>
      </InputOTP>
      <FieldDescription>We sent it to ada@example.com.</FieldDescription>
      <FieldError errors={error ? [{ message: error }] : []} />
    </Field>
  )
}
```

## Props in this example

### InputOTP

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `length` | `number` | – | Required. The number of slots; render the same number of InputOTPSlot parts. |
| `value` | `string` | – |  |
| `onValueChange` | `(value: string, details) => void` | – |  |
| `onValueComplete` | `(value: string, details) => void` | – | Called when the last slot fills. |

## More Input OTP examples

- [Joined](https://hextaui.com/docs/input-otp/examples/basic.md)
- [Separate](https://hextaui.com/docs/input-otp/examples/separate.md)
- [Sizes](https://hextaui.com/docs/input-otp/examples/sizes.md)
- [Animated](https://hextaui.com/docs/input-otp/examples/animated.md)
- [Status](https://hextaui.com/docs/input-otp/examples/status.md)
- [Controlled](https://hextaui.com/docs/input-otp/examples/controlled.md)
- [Form](https://hextaui.com/docs/input-otp/examples/form.md)
- [Invalid](https://hextaui.com/docs/input-otp/examples/invalid.md)
- [Letters and numbers](https://hextaui.com/docs/input-otp/examples/alphanumeric.md)
- [Masked](https://hextaui.com/docs/input-otp/examples/masked.md)
- [Custom separator](https://hextaui.com/docs/input-otp/examples/custom-separator.md)
- [Disabled](https://hextaui.com/docs/input-otp/examples/disabled.md)
- [Right to left](https://hextaui.com/docs/input-otp/examples/rtl.md)
