How do I return values that have not been validated? #206
Replies: 2 comments
-
The best way, I think, would be to allow a function like |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What is needed for: for progressive improvement and improvement of DX users.
When returning a value, you can insert the values that users entered back into place and it works fine if you return them from server actions
Possible ways
OnError
On Error returns void, why can't I return what came from the client in the form of
clientInput
Metadata
It needs to be validated using the client and from which it is used for all server actions (And she doesn't have access to basically anything)
a function inside the utils of the schema method (handleValidationErrorsShape)
He already gets an error, which is why there is no access to the initial information
Middleware
It does not allow you to return the context or anything in case of a validation error
Conclusion: The
schema
method needs to be changedI think it needs to be reworked.
Firstly, it is inconvenient to do each scheme in this way if you want to support progressive improvement (instead of onSubmit):
Secondly, with this method, which is now, it is impossible to return any values, even manually
You can try to change the logic of the schema. For example, when using a callback, take the previous one to the scheme, and for example the processing stage (that is, the argument will be the information received before the schema method)
because, for example, I don't see the point in expanding the scheme. This can be done without the schema method anyway, although maybe I don't understand something. Provided that this extension hopefully doesn't work every time a server action is called
why else is it convenient, for example, to make an information processing function instead of supplementing the scheme? You can use functions such as: zfd.processFormData (which is used inside zfd.formData) to parse form Data into an object and return it as parseInput.
zfd.processFormData will just allow you to pull the fields you need and send them as an object and allows you to use the normal schema instead of zfd.formData()
P.S. well, or give the user the opportunity to return something from onError
P.S2 Or ask zod developers to return incorrect values in case of an error, not validated values
Beta Was this translation helpful? Give feedback.
All reactions