-
Notifications
You must be signed in to change notification settings - Fork 32
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
Pass the field/key when errorMessage is a function #89
Pass the field/key when errorMessage is a function #89
Conversation
I like the approach, very nice example of how to create a const typeRule = (type) => [
isType(type),
(val, field) => typeMessage(type, field)
]; Just so I fully understand, this: const isType = R.curry((type, field) => R.type(field) === type); should be: const isType = R.curry((type, val) => R.type(val) === type); right? |
Exactly! Sorry, my bad. |
Yes, I think this is very cool! |
We should add this to the const validationRules = {
name: [typeRule("String")]
} shows how nicely one can create rules. |
@Emilios1995 Great work! |
Thanks, I'm glad you liked it! |
We should also document this in the API docs. I'll probably make a commit for that later. |
We should als add a test, but I can write that one tomorrow, if you have no time for that. |
@busypeoples I'll try to do both things tonight. I'll ping you tomorrow if I have any trouble. |
Done! But I'm not sure if I left that test too complex or the docs too verbose. What do you think? P.S. I would also love to see something like my |
@Emilios1995 Thank you very much! |
Regarding the |
It is very common to include the name of the field in the error message.
I thought it convenient to include pass it when errorMessage is a function.
Here's how I'm using this feature (from my fork):