Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom validator error names #50

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

eden-omb
Copy link

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
Copy link
Author

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.

@chainlist
Copy link
Owner

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

@eden-omb
Copy link
Author

eden-omb commented Feb 3, 2022

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.

@martinmunillas
Copy link

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

@martinmunillas
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants