-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add client side validation #1
Comments
Hey @kirill-konshin glad you enjoyed the post and interesting you hit the exact same solution. :) Thanks for sharing this, leaving out client-side validation was a bit of an omission. |
Of course! Collaboration is what moves industry forward. |
Added: https://rdrn.me/react-forms/#client-validation And added to the repo as well: 71ba020 Having to return |
Thanks for the mention!
Res is basically server returning what it received, along with errors, can be useful sometimes. Since solution is zod-centric its error structure as return seems to be OK. Besides, people who work with zod are well aware of it. |
I was writing an article on React 19 forms and Zod, and before submission I decided to do one more round of googling, if something similar already exists... and found your wonderful article.
Fun thing is that I ended up with almost exactly the same implementation as you, almost line by line the same where it matters.
So I'd like to share how I implemented client side validation, it's just a few more lines of code to what you already have.
If you extract validation from server action into a validation function, you can call it on client side as well, before calling server action ;)
Just make sure it's not in actions file, as it's marked as
"use server";
, probablytypes.ts
is the right place for it.So your action becomes:
and on client side:
This way you save a roundtrip to server and apply exactly the same validation in both realms.
The text was updated successfully, but these errors were encountered: