Validation Requirement changes
nanaeasiedu opened this issue · comments
I had an situation where the validator
passed to thefield
had to change depending on other changes in other parts of the form
.
Unfortunately, since we register the validator
function once during componentDidMount
, it can't pick up changes in the validator
function. https://github.com/zero-plus-x/neoform/blob/master/packages/neoform-validation/src/fieldValidation.js#L18
I had to implement componentWillReceiveProps
in the fieldValidation
to check if there are any differences in the validator
function and register the new function.
componentWillReceiveProps(nextProps) {
if (nextProps.validator && nextProps.validator !== this.props.validator) {
this.context.neoform.registerValidator(this.props.name, nextProps.validator);
}
}
I might be doing this wrong, I will be glad if there is another way. Thanks.
Sounds reasonable, I'll take a look and probably just merge your code snippet 👍
Just landed with neoform-validation@0.4.2. Thanks!