Migrating to 5.0
Follow these steps to have a seemless migration from 4.x to 5.0
install a strategy
react-validation-mixin is now extendable via strategies. You will need to install the joi-validation-strategy separately.
> npm install --save joi-validation-strategy
OR
> yarn add joi-validation-strategy
export your component
Wrap the component with the validation mixin and supporting strategy on export:
export default validation(strategy)(Component);
this.validatorTypes and this.getValidatorData
Implement both validatoryTypes
and getValidatorData
: (Invariants will be thrown when these methods are not implemented)
validatorTypes = {
username: Joi.string().alphanum().min(3).max(30).required().label('Username'),
password: Joi.string().regex(/[a-zA-Z0-9]{3,30}/).label('Password')
}
getValidatorData() {
return this.props;
}
this.getValidationMessages
This method no longer returns an array; unless the datatype is an array.
{this.renderHelpText(this.props.getValidationMessages('password'))}
this.props
Your component will now receive the validation API as props.
propTypes = {
errors: PropTypes.object,
validate: PropTypes.func,
isValid: PropTypes.func,
handleValidation: PropTypes.func,
getValidationMessages: PropTypes.func,
clearValidations: PropTypes.func,
};