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
I wanted to display some custom errors from my API.
I made a name space called formErrors that contains these generic errors, and when an error occurs I then check if formErrors has an translation for it and if so, I translate it with i18next.
However, some erorrs needs more context (parms), like my custom TOO_SHORT_PASSWORD that is a Zod type like string().min(8, "TOO_SHORT_PASSWORD"), which in my formErrors hans a translated string `The password should be at least {{ minimum }} characters long".
This works, I think I have misunderstood something, or done it wrong. With my implementation I miss out of some of the functionality of this package like exact, inclusive and not_inclusive.
Is there a way I can have custom error messages, with interpolation, that doesn't require the refine/params method?
The text was updated successfully, but these errors were encountered:
I discovered that the error mapping function is not invoked when you already have message set, i.e. the message field, if provided, is guaranteed to be untouched. This behavior is at zod's side, so I do not think it is possible for this package to intercept your custom message in any way.
That said, I wonder if adding an extra layer after form validations fits into your use case; to check each issue for a code field from zod and call i18n at this moment.
Hi,
I wanted to display some custom errors from my API.
I made a
name space
calledformErrors
that contains these generic errors, and when an error occurs I then check ifformErrors
has an translation for it and if so, I translate it withi18next
.However, some erorrs needs more context (parms), like my custom
TOO_SHORT_PASSWORD
that is a Zod type likestring().min(8, "TOO_SHORT_PASSWORD")
, which in myformErrors
hans a translated string `The password should be at least {{ minimum }} characters long".This works, I think I have misunderstood something, or done it wrong. With my implementation I miss out of some of the functionality of this package like
exact
,inclusive
andnot_inclusive
.Is there a way I can have custom error messages, with interpolation, that doesn't require the refine/params method?
The text was updated successfully, but these errors were encountered: