-
Notifications
You must be signed in to change notification settings - Fork 20
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
Component Props within validator #17
Comments
Hi, @vinayrajp! There isn't a built-in way to access the component props. However, you could wrap your validate function with another function and then merge the values and props into one object that you pass in to your validate function. I believe that should work. const validator = combineValidators({/* validation definition */});
function validate(values, props) {
return validator({ ...values, ...props });
} If you want to keep values and props separate, then you could pass them in as sub objects. You would then define your validate function in the terms of that. const validator = combineValidators({
'props.name': isRequired('Name Prop'),
'values.age': isRequired('Age Value'),
});
function validate(values, props) {
return validator({ values, props });
} Does that help? |
Closing due to inactivity. If the suggested example doesn't/didn't help, please let me know. |
@jfairbank can you please provide more examples... Thanks |
Hello Jeremy,
Thanks for creating revalidate. I really love how the validators can be combined and reused. Keep up the good work.
This is more of a question than an issue. Redux-form's validate function is as follows:
validate : (values:Object, props:Object) => errors:Object [optional]
My question is about the second argument props which can be utilized if the component's props are needed within validation. How can the component props be passed to createValidator/composeValidator/combineValidators, so that it can be used in validation? Is this even possible?
Thanks once again.
Vinay.
The text was updated successfully, but these errors were encountered: