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

errorHelp flexibility for showing multiple error messages from custom validation function #28

Open
aghreed opened this issue Jan 21, 2016 · 2 comments

Comments

@aghreed
Copy link

aghreed commented Jan 21, 2016

So I have a custom validation function for a password input, and want to show the user which of the four field validation rules the current value of the input is not meeting.

From what I can tell there is not support for doing this currently. I can return a string value from the validate function that gets displayed (awesome!), except for when I have multiple validation rules being broken, in which case my errorHelp text is just one long string which isn't too readable. I would like to have them on separate lines (really separate divs) like the errorHelp is displayed when you have multiple validation rules applied to an input that are from validator.js.

I think a pretty awesome feature (which I'm willing to put time in to make a PR if it is well received), would be to try and look for the string that is returned from the validate function to match a key in the errorHelp object, and then display the corresponding value as the error message.

For others that have had similar issues, I am getting around this for the moment by just passing jsx into the errorHelp prop. It breaks the propTypes, but it does work!

Anyways, let me know what you think.

@heilhead
Copy link
Owner

Can't see how looking up string returned from validate method in errorHelp object could solve this problem. Could you provide an example?

I think the proper way would be to accept an array as a result of validate call and do this only in validate method, not with generic rules of validator.js, because otherwise all fields would be polluted with something like this:
'Please enter your email'
'Email is invalid'

Or like this:
'Please specify a password'
'Password must be at least 6 characters'

The idea is good overall, but should not break existing forms with showing too much errors.

@aghreed
Copy link
Author

aghreed commented Jan 25, 2016

Certainly. I think we are saying something to the same extent. Regardless, I'll see if I can find some time this week to make a PR. Thanks for getting back so quickly.

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

No branches or pull requests

2 participants