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

Allow a Validator or CustomValidator to dynamically generate error messages. #45

Open
sten-navie opened this issue Apr 11, 2019 · 0 comments

Comments

@sten-navie
Copy link

Currently one can create custom Validators using CustomValidator, where one specifies a predicate and an error message in case the predicate fails. In some cases it would be useful to generate a custom message based on the failed input. Basically indicating more specifically what is wrong with the input-string.

E.g. I have a field for inputting an ipv4 network-prefix, if the first octects are ok, but the last octet is not compatible with the network mask, I want to indicate what the closest valid numbers are for the last octet, instead of just reporting that the input value is not compatible with the provided mask.

Ideas for how this could be solved:

  • Open up the ValidationResult constructor or add a static factory-method taking the error message as a parameter. This would allow one to create Validators by just implementing Validator (given that there also would be a public way to generate an OK result.
  • Modify CustomValidator somehow to allow modifying the error message before creating the result. E.g. by providing an optional error-message generator function taking the input value and returning a message.
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

No branches or pull requests

1 participant