Verify and upload4 checks

FormFile

Drop zone with type, size and count rules.

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

Needs the @fieldkit registry. Add it once

Usage
  1. 1

    Add the field to your schema

    schema.ts
    import { z } from "zod"import { fileField } from "@/lib/field-schemas"
    export const schema = z.object({  cv: fileField({ accept: { "application/pdf": [".pdf"] }, maxSize: 5 * 1024 * 1024 }),})
  2. 2

    Render it inside a Form

    The name prop matches the schema key.

    example-form.tsx
    import { Form } from "@/components/form/form"import { FormFile } from "@/components/form/form-file"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={{ cv: [] }}      onSubmit={save}    >      <FieldGroup>        <FormFile name="cv" />        <FormSubmit>Save</FormSubmit>      </FieldGroup>    </Form>  )}
Checks
RequiredminChoose a file
File typeacceptcv.docx is not a supported file type
SizemaxSizecv.pdf is over 5 MB. Choose a smaller file.
Number of filesmaxFilesUpload up to 3 files
Best practices
  • Pass existing and onRemoveExisting to show saved files when editing
  • Check the type again on the server
Try these values
Terminal
fileField({ accept: { "application/pdf": [".pdf"] }, maxSize: 1024 })
InputResultOutput
["cv.pdf, 512 B"]Valid["cv.pdf, 512 B"]
["big.pdf, 2048 B"]Invalid
One of the files is too large
[]Invalid
Choose a file
API reference

FormFile

acceptFileAcceptFile types, as words or MIME map.
existingArray<{ id, name, url?, type? }>Files already saved, for edit forms.
onRemoveExisting(id: string) => voidCalled when a saved file is removed.

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