Created
October 10, 2016 05:56
-
-
Save seangoedecke/456c965827ceeda1fc74ab1f70fea0e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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