Open aghreed opened 8 years ago
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.
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.
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 theerrorHelp
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.