svelte-forms icon indicating copy to clipboard operation
svelte-forms copied to clipboard

Add custom validator error names

Open eden-omb opened this issue 3 years ago • 5 comments

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").

eden-omb avatar Jan 20 '22 13:01 eden-omb

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.

eden-omb avatar Jan 29 '22 15:01 eden-omb

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

chainlist avatar Jan 29 '22 22:01 chainlist

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.

eden-omb avatar Feb 03 '22 11:02 eden-omb

I was about to do this same PR because I loved the library but hated the error mapping part

martinmunillas avatar Mar 17 '23 08:03 martinmunillas

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

martinmunillas avatar Mar 17 '23 08:03 martinmunillas