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
If my understanding is correct, validator returned by createServerValidate (no matter the framework) does not run validators defined in the defaultOpts parameter.
I'm starting this this discussion because my initial assumptions were that the returned validator would run the onServerValidateand other validators defined in defaultOpts, so that when I've successfully validated formData in server action, I could be sure that the data made it through all defined validations, like so:
exportasyncfunctionaction({ request }){constformData=awaitrequest.formData()try{constvalidatedData=awaitserverValidate(formData)// Here I would like to be sure that validatedData is compatble with userSchema }catch(e){// ...}// ...}constuserSchema=z.object({age: z.number().gte(13,'You must be 13 to make an account'),})constformOpts=formOptions({defaultValues: {/**...*/},validators: {onChange: userSchema,},})constserverValidate=createServerValidate({
...formOpts,onServerValidate: ({ value })=>{// ... server logic},})
This would be my preferred workflow, but I know it has its limitations. I would just like to know if it is something that could be implemented in the future, or if someone has a nice way to share validations between client and server. I know I could simply parse the schema after the serverValidate call, but I would have to do that everywhere after I call that function.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
If my understanding is correct, validator returned by
createServerValidate
(no matter the framework) does not run validators defined in thedefaultOpts
parameter.I'm starting this this discussion because my initial assumptions were that the returned validator would run the
onServerValidate
and other validators defined indefaultOpts
, so that when I've successfully validated formData in server action, I could be sure that the data made it through all defined validations, like so:This would be my preferred workflow, but I know it has its limitations. I would just like to know if it is something that could be implemented in the future, or if someone has a nice way to share validations between client and server. I know I could simply parse the schema after the
serverValidate
call, but I would have to do that everywhere after I call that function.Thanks!
Beta Was this translation helpful? Give feedback.
All reactions