react-bootstrap-validation icon indicating copy to clipboard operation
react-bootstrap-validation copied to clipboard

`errorHelp` flexibility for showing multiple error messages from custom validation function

Open aghreed opened this issue 9 years ago • 2 comments

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.

aghreed avatar Jan 21 '16 16:01 aghreed

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.

heilhead avatar Jan 23 '16 07:01 heilhead

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.

aghreed avatar Jan 25 '16 16:01 aghreed