-
Using
Having this schema const TournamentSchema = object({
TournamentID: number().defined().required(),
LeagueID: number().defined().required(),
League: LeagueSchema.defined().required(),
SeasonID: number().defined().required(),
Season: SeasonSchema.defined().required(),
Name: string().defined().required().min(1),
}) When using As soon as I am using this kind of resolver from the docs, I can see all errors in the console output
Then in render
Now the situation is totally normal, but why is the error object empty ? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 3 replies
-
Can you share a reproducible example vi CodeSandbox please? |
Beta Was this translation helpful? Give feedback.
-
Please read carefully the documentation Error can only be mapped if it was registered with react-hook-form. In your example, even with built-in yup resolver or your custom yup resolver, there is only one input "Name" has been registered, therefore react-hook-form cannot validate and show error of what it does not know. |
Beta Was this translation helpful? Give feedback.
-
I have the same issue, and maybe I misunderstand something, but I cannot solve this issue on this form. I have simple a resolver: yupResolver(
yup
.object()
.shape({
withdrawalType: yup
.string()
.required(t('resources.users.edit.withdrawal.dialog.validation.type')),
})
.required(),
) And I have only one input field what is a MUI `ButtonGroup ̇, and when I see this code's output: const { watch, getFieldState, getValues } = useFormContext();
const { dirtyFields, isValid } = useFormState();
console.log(
watch(),
isValid,
getFieldState('withdrawalType'),
); I got this: Object { withdrawalType: "/api/withdrawal_types/2" }
false
Object { invalid: false, isDirty: true, isTouched: true, isValidating: false, error: undefined } My question is, what have I missed? (Now, I have a workaround for this, to see all field states...) |
Beta Was this translation helpful? Give feedback.
-
Usingzod 3.25.32 Issue descriptionI'm facing the same issue. In my case, I have the validation mode as When I click submit, there are no errors shown but it's not in valid state. As soon as I change some value (does not matter which one) and submit again, it becomes valid. I did a JSON diff of form values & form changes, for the above 2 cases and the only change was the latest value that I changed. PS: I'm sure this is something that I'm missing or have done wrong but there has to be a better way to help debug. Workaround CodeAs a workaround, in my submit function I check if the form is invalid and there are no form errors then I just call form.trigger() and then recursively call the submit function again with the retry flag as false.
RHF HandleSubmit
|
Beta Was this translation helpful? Give feedback.
-
try trigger the form validation again once all the values are set |
Beta Was this translation helpful? Give feedback.
@iongion
Please read carefully the documentation
Error can only be mapped if it was registered with react-hook-form. In your example, even with built-in yup resolver or your custom yup resolver, there is only one input "Name" has been registered, therefore react-hook-form cannot validate and show error of what it does not know.