#ValidationError - Zod

10 messages · Page 1 of 1 (latest)

lean forge
#

I'm wondering why ValidationError doesn't return an array of strings, where each item is an error?
According to this screenshot I'm expecting an array like [ "Password, must contain at least 8 characters" , "Password, must include tuna" ]
It looks always return 1 item with the errors concat with , . The thing is, I want to display 1 error at the time, not all of them for a better UX. If I do it in a hacky way extracting the items based on , it won't work for error messages where I add a comma. Is there any workaround for this?

prime jasper
#

Looks like it could be a problem with the Zod adapter maybe? Because ValidationError isn't meant to be an array

lean forge
prime jasper
#

I don't know, because you haven't provided much info about your setup

lean forge
prime jasper
#

Looks like the zod adapter is the one that is smooshing them together

south vale
#

If you want more controls on the errors you can pass a transformErrors function to the adapter. With zod might look like this to only get the first:

    validatorAdapter: zodValidator({
      transformErrors: (errors) => errors.map((error) => error.message)[0]
    }),
lean forge
lean forge
south vale
#

Yes it's the default behavior