Get errors through props instead of context

This commit is contained in:
SachaG 2018-03-28 11:14:15 +09:00
parent 5705de3559
commit ce7e0b0b25
2 changed files with 10 additions and 4 deletions

View file

@ -90,7 +90,7 @@ class FormComponent extends PureComponent {
*/
getErrors = () => {
const fieldErrors = this.context.errors.filter(error => error.data.name === this.props.path);
const fieldErrors = this.props.errors.filter(error => error.data.name === this.props.path);
return fieldErrors;
};
@ -194,7 +194,7 @@ class FormComponent extends PureComponent {
value: '',
disabled: true,
};
console.log(properties.options)
properties.options = [noneOption, ...properties.options];
return <Components.FormComponentSelect {...properties} />;
@ -285,7 +285,8 @@ FormComponent.propTypes = {
path: PropTypes.string,
disabled: PropTypes.bool,
nestedSchema: PropTypes.object,
nestedFields: PropTypes.array,
currentValues: PropTypes.object,
errors: PropTypes.array,
};
FormComponent.contextTypes = {

View file

@ -32,7 +32,11 @@ class FormGroup extends PureComponent {
}
render() {
const hasErrors = _.some(this.props.fields, field => field.errors && field.errors.length);
// if at least one of the fields in the group has an error, the group as a whole has an error
const hasErrors = _.some(this.props.fields, field => {
return !!this.props.errors.filter(error => error.data.name === field.path).length
});
return (
<div className="form-section">
@ -45,6 +49,7 @@ class FormGroup extends PureComponent {
updateCurrentValues={this.props.updateCurrentValues}
formType={this.props.formType}
currentValues={this.props.currentValues}
errors={this.props.errors}
/>
))}
</div>