svelte-forms
svelte-forms copied to clipboard
Add custom validator error names
Title, basically. Currently it's impossible to override the uninformative and unlocalized validation errors. When unsatisfied, the required() validator simply prints required, a bad URL prints url, invalid email prints not_an_email, etc.
This PR adds the ability to pass along a custom name, such that one could optionally call e.g. between(5, 10, "Must be between 5 and 10").
Currently I can live without this by mapping the validation error name to the error message I want, but it seems like an extra step that could be done without.
Hi @eden-omb,
Thanks for your PR. I'm currently reviewing what your changes imply for the rest of the code and futur improvements.
I'll get back to you as soon as I can
Excellent! I'm really not sure if this is the best way to go about this, and doesn't really solve things like the not validator. In my own code I'm just mapping validator names to i18n keys. Nevertheless this seemed like a good jumping board to start solving this in svelte-forms, because this really feels like something that should be a feature.
I was about to do this same PR because I loved the library but hated the error mapping part
please @chainlist let me know how I can help this move forwards, I think this change won't affect negatively to anyone, is just an extra feature that is not required of use by anyone that doesn't want to