WhenDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/rijvi-mahmud/shaddy/llms.txt
Use this file to discover all available pages before exploring further.
ShaddyForm renders, it wraps its children with react-hook-form’s Form provider (the shadcn/ui wrapper around FormProvider), making the full form instance available throughout the component tree. Field components tap into this context to register themselves, display validation errors, and read current values — all without receiving any form props directly from their parent.
How FormContext Works
ShaddyForm calls useForm() internally and renders <Form {...form}>, which is the shadcn/ui Form component that wraps react-hook-form’s FormProvider. Any component inside ShaddyForm can therefore call useFormContext() to access the full UseFormReturn object — including control, register, getValues, setValue, formState, and more.
The form-context.ts file also exports a narrower typed context and hook for scenarios where you want to build utilities that only depend on the control object:
useShaddyFormContext reads from a separate ShaddyFormContext that is not automatically provided by ShaddyForm. To use it, you must render ShaddyFormContext.Provider yourself. For most use cases — including all built-in field components — use react-hook-form’s useFormContext() instead, which works out of the box inside any ShaddyForm.useFormContext() for Custom Fields
The primary way to build a custom field is to call useFormContext<T>() inside your component. This gives you the control object to pass to FormField, as well as any other form method you need.
useFormContext reads from the nearest form provider, this component works anywhere inside a ShaddyForm regardless of how deeply nested it is — no prop drilling required.
Accessing Form Values in Non-Field Components
You can useuseFormContext in any component inside ShaddyForm, not just fields. For example, a review step in a multi-step form can read submitted values without triggering re-registration:
ShaddyForm and it will automatically receive the live form data.
useTriggerForm — Programmatic Step Validation
useTriggerForm is a custom hook designed for multi-step forms. It wraps react-hook-form’s form.trigger() method in a convenience function that accepts the form instance and an array of field paths to validate, returning a structured result object.
Return Value
true if any of the specified fields failed validation, false if all fields are valid.A human-readable error message when
hasError is true. This is a generic message, not the field-level error — individual field errors are displayed by each field’s FormMessage component.Usage in a Multi-Step Form
Step component’s validate prop expects a function that returns { hasError: boolean }. When hasError is true, the stepper stays on the current step and each field displays its own validation error message automatically.
useTriggerForm requires access to the ShaddyFormRef — it does not use useFormContext. This is intentional: it is designed to be called from outside the form context (e.g., in a parent component or a stepper controller), not from within a field component.