Skip to content

Instantly share code, notes, and snippets.

@seangoedecke
Created October 10, 2016 05:56
Show Gist options
  • Save seangoedecke/456c965827ceeda1fc74ab1f70fea0e0 to your computer and use it in GitHub Desktop.
Save seangoedecke/456c965827ceeda1fc74ab1f70fea0e0 to your computer and use it in GitHub Desktop.
const FormAddon = () => {
return(
<div>
<Field name = 'addonField' component={renderField} label="Addon label" type="text" placeholder="add on placeholder" />
</div>
)
}
const validateFormAddon = (values) => {
console.log("validating!")
const errors = {}
if (!values.addonField) {
errors.addonField = 'Required'
}
return errors
}
const validateMain = (values) => {
let errors = {}
if (!values.lastName) {
errors.lastName = 'required...'
}
return errors
}
const mergeValidators = (...validators) => {
return (values) => {
let errors = {};
validators.forEach( (validator) => {
errors = Object.assign(errors, validator(values));
});
return errors;
};
}
export default reduxForm({
form: 'simple', // a unique identifier for this form
validate: mergeValidators(validateFormAddon, validateMain)
})(SimpleForm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment