You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran into an issue on react-hook-forms valibot resolver. The bug itself is a result of the resolver but I think there's maybe a small design flaw in valibot that is the root cause so I wanted to ask about it here.
For most cases, this isn't an issue. We'll throw an error saying that because the type isn't set we can't select a variant to validate with.
For form validation libraries though it's likely that type isn't set and that we're trying to validate it. It's expected behaviour that type could be undefined, it's also expected that the this should fail with a path set so we can map it back to the field that hasn't set it properly.
Because variant isn't a validation but a schema by design, the validation path isn't set and the only options the users have are:
Have a default value always
Fix the issue in react-hook-form (which I will also file a bug for) but not map the error back to the field.
Some other workaround on the users side. Maybe some sort of pre-processing?
Zod does address this as validation error through discriminatedUnion and I think that's the correct approach.
The text was updated successfully, but these errors were encountered:
Thank you for creating this issue. variant is the same as discriminatedUnion in Zod. I think we can solve this problem for Valibot by adding a path pointing to the discriminator key in the issue object. That way the resolver will automatically add the error message to the right field.
Hey @fabian-hiller thanks for the fast response. I've submitted a PR for the resolver above. I would help here too but I don't know enough about the repos structure and how you might want to address it but let me know if there's anything else I can do.
I ran into an issue on react-hook-forms valibot resolver. The bug itself is a result of the resolver but I think there's maybe a small design flaw in valibot that is the root cause so I wanted to ask about it here.
The issue is that the schemaIssue() does not return a path. As a result, there's an exit condition that's not being addressed in the resolver. So there's two sides to this bug and I think there's a case for addressing it here.
Take a look at this simplified schema:
For most cases, this isn't an issue. We'll throw an error saying that because the type isn't set we can't select a variant to validate with.
For form validation libraries though it's likely that type isn't set and that we're trying to validate it. It's expected behaviour that type could be undefined, it's also expected that the this should fail with a path set so we can map it back to the field that hasn't set it properly.
Because variant isn't a
validation
but aschema
by design, the validation path isn't set and the only options the users have are:Zod does address this as validation error through
discriminatedUnion
and I think that's the correct approach.The text was updated successfully, but these errors were encountered: