Number and date3 checks

FormNumber

Numbers with min, max and whole-number checks. Empty is null.

Example
Installation
bunx --bun shadcn@latest add @fieldkit/form-number

Needs the @fieldkit registry. Add it once

Usage
  1. 1

    Add the field to your schema

    schema.ts
    import { z } from "zod"import { numberField } from "@/lib/field-schemas"
    export const schema = z.object({  age: numberField({ min: 13, max: 120, integer: true }),})
  2. 2

    Render it inside a Form

    The name prop matches the schema key.

    example-form.tsx
    import { Form } from "@/components/form/form"import { FormNumber } from "@/components/form/form-number"import { FormSubmit } from "@/components/form/form-submit"import { FieldGroup } from "@/components/ui/field"import { schema } from "./schema"
    export function ExampleForm() {  return (    <Form      schema={schema}      defaultValues={{ age: null }}      onSubmit={save}    >      <FieldGroup>        <FormNumber name="age" />        <FormSubmit>Save</FormSubmit>      </FieldGroup>    </Form>  )}
Checks
RequireddefaultEnter a number
Rangemin, maxEnter a number of at least 13
Whole numbersintegerEnter a whole number
Best practices
  • Never use it for phone, card or ID numbers
  • Ignores the scroll wheel so values do not change by accident
Try these values
Terminal
numberField({ min: 13, max: 120, integer: true })
InputResultOutput
30Valid30
12Invalid
Enter a number of at least 13
121Invalid
Enter a number of at most 120
30.5Invalid
Enter a whole number
nullInvalid
Enter a number
API reference

FormNumber

...input propsReact.ComponentProps<"input">min, max and step default to the schema rules.

Field frame

namestringKey in the schema. Also picks the preset label and autocomplete.
labelReact.ReactNodeOverrides the preset label. Pass null to hide it.
descriptionReact.ReactNodeHint under the control.
requiredbooleanOverrides the asterisk read from the schema.
fieldPropsFormFieldPropsProps for the wrapping Field, such as className.

Search docs

Find a component, input or example