Troubleshooting
Common symptoms, their causes and their fixes. To look up an error, search this page for its wording.
On this page
スキーマにあるフィールドが送信されていません
Cause
parseForm throws this error when a field in the schema is not in the submitted FormData. Usually its input was not spread, or the field is not rendered under some condition.
Fix
Spread input onto every field, and render the fields inside an .optional() object too. A radio group with nothing selected and a <select> on its placeholder are read as no value, and an unchecked checkbox as false. None of them raises this error.
Empty field rejected despite .optional()
Cause
An empty text field submits "". .optional() only allows a missing value, so a check such as .min(1) still runs against "".
Fix
To allow an empty field, write a schema that accepts "", such as z.union([z.literal(''), z.string().min(3)]). The .min(3) is inside a union, so the browser does not check it and it is listed in dropped.
Invalid input
Cause
zod/mini does not load a message locale on its own. Without one, every error reads Invalid input.
Fix
Load a locale with z.config(z.locales.en()) in a module the server loads first. Or write a message on each check in the schema.
Radio selection not restored
Cause
The enum’s input is spread whole onto a hand-written <input type="radio">. After a submission, input carries the previous choice as defaultValue. That collides with each radio’s own value, so no selection is restored.
Fix
Take only name and required from input. Set defaultChecked per option by comparing it with the value in state.values.
Focus not moving on a repeated failure
Cause
useForm tells responses apart by their content and token. A hand-built state without a fresh token makes a second identical failure look like the same response.
Fix
Return the state from parseForm unchanged. When building one by hand, give it a fresh token every time.
Focus on a hidden step
Cause
A field inside a hidden step cannot take focus.
Fix
When a new state arrives, switch during render to the first step holding an error. The steps are in Multi-step forms.