Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Qwik] Zod async validation doesn't work #233

Closed
Martinusius opened this issue Aug 2, 2024 · 3 comments
Closed

[Qwik] Zod async validation doesn't work #233

Martinusius opened this issue Aug 2, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@Martinusius
Copy link

When using custom async validation function in zod (using .refine) the form throws an error saying that .parseAsync should be used for the validation.

image

Async validation has many use cases. I personally encountered this issue while trying to implement username taken check during user registration.

The issue can presumably be traced to this file: /packages/qwik/src/utils/getParsedZodSchema.ts

image
In this file the .safeParse function is always used to parse the data, even when async validation is needed.

It seems however that a very simple fix is possible:
image
We can always use the async version .safeParseAsync instead since the original function is always async anyway.

As far as I know this approach has no downsides and successfully fixes the issue at hand.

@fabian-hiller
Copy link
Owner

fabian-hiller commented Aug 3, 2024

I am not sure why I did not implement it with .safeParseAsync. I think there was a reason, but I am not sure anymore. I will see if I can change it to .safeParseAsync and release a new version. As a workaround you can simply copy the code, change it to the async version and use your own adapter until the new version is available.

@fabian-hiller fabian-hiller self-assigned this Aug 3, 2024
@fabian-hiller fabian-hiller added the enhancement New feature or request label Aug 3, 2024
@fabian-hiller
Copy link
Owner

I plan to work on this issue today.

@fabian-hiller
Copy link
Owner

A new version is available

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants