toolmark-monorepo / @toolmark/react/rhf / rhfAdapter
Function: rhfAdapter()
rhfAdapter<
V>(form,opts):FormAdapter<V>
Defined in: packages/react/src/rhf/index.ts:111
Bridges a react-hook-form useForm() instance to Toolmark form tools (spec §8.1, §9).
Reads form.formState.dirtyFields once, synchronously, when the adapter object is constructed: react-hook-form's formState is a Proxy that only tracks the fields it has been read for (dirtyFields included), so useFormTool (which builds the adapter during render, before any effect) enables this tracking even when the host component never reads formState itself.
Tour hooks (spec §13): onUserInteraction reports input for react-hook-form's own user-change signal (watch with type: 'change', never the adapter's setValue writes) and, when opts.root is given, focus for trusted focusin on named elements inside root() and submit for a trusted submit event inside it. Only paths are reported, never values.
inputfollows react-hook-form's own change signal, not the DOM event: a syntheticonChangefrom page script (or a component library callingfield.onChange) is reported as a userinputtoo. Only the DOMfocus/submitreports checkisTrusted.- Sensitivity (spec §14): with elements (
root/elementFor), a path whose element was ever seen as a password /cc-*/ secret-autocompleteinput stays redacted for the adapter's lifetime, so a "show password" toggle (type="password"→"text") never exposes it instate(). A path is only known once its element has been seen that way; withoutroot/elementFornothing is detected, so declare secret paths in the form tool'ssensitive.
Type Parameters
V
V extends FieldValues
Parameters
form
UseFormReturn<V>
The useForm() return value.
opts
See RhfAdapterOptions.
Returns
FormAdapter<V>