Multiple error messages
I'm trying to migrate a zod schema to arktype. This is the zod schema I have:
If any of these checks fail, Superforms will provide me with a
$allErrors
for the password field that will be an array like ['lenght', 'uppercase'], which in turn I can use in my i18n layer.
I'm trying to achieve the same behaviour with Arktype, but I can't have a different error being reported, or even trim the error message down to a word, for my i18n layer.
This is what I have so far, which I know it does not work:
any thoughts on how I can achieve this?Superforms
Superforms - Form library for SvelteKit
7 Replies
My first thought would be to configure
message
instead of describe
so that it will replace the entire output:
https://arktype.io/docs/configuration#errors
Let me circle back tomorrow and take a look at mapping the errors by field to the list of messages.
It's really useful for me to have context on i18n/forms integrations like this so I know what utilities to provide on ArkErrors
. There's lots of introspectability there currently but if there's way I can organize it so it integrates more easily into existing solutions like this I'm all for itwe currently use this approach to do something like this with our i18n layer:
Oh wow this shows me how little I know about Svelte syntax haha but I do still want to think about mapping to i18n codes... if I haven't taken a stab at some mapping by Monday please ping me!
here's the ping you requested @ssalbdivad 🙌
Hey sorry for the delay! It seems like something like this should work:
Would definitely be interested in building in an API for making this a bit easier since I can see how this is a useful pattern for i18n.
wonderful! let me know if there's anything I can do to help
Actually if you want to create an issue with this example and my recommended workaround, that would be a good place to track this work and to potentially propose APIs that would solve the problem more elegantly