Skip to content

Commit

Permalink
EncounterForm Obs: update fields after any changes to validations
Browse files Browse the repository at this point in the history
  • Loading branch information
mogoodrich committed Jul 18, 2019
1 parent e4e7160 commit 8cc6f11
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/components/form/Obs.jsx
Expand Up @@ -36,15 +36,27 @@ class Obs extends React.PureComponent {
}

componentDidUpdate(prevProps) {
// reset the validation after loading the concept
if (!prevProps.concept._openmrsClass && this.props.concept._openmrsClass) {
// reset the validation after loading the concept, or if any of the validation ranges have changed
if ((!prevProps.concept._openmrsClass && this.props.concept._openmrsClass) || this.validationRangesChanged(prevProps)) {
this.setState({
getValidationAbnormalRange: formValidations.generateAbnormalAndCriticalWarningFunctions(this.props.concept),
getValidationAbsoluteRange: formValidations.generateAbsoluteRangeValidators(this.props.concept)
});
}
}

validationRangesChanged(prevProps) {
if (prevProps.concept.hiNormal !== this.props.concept.hiNormal
|| prevProps.concept.lowNormal !== this.props.concept.lowNormal
|| prevProps.concept.hiCritical !== this.props.concept.hiCritical
|| prevProps.concept.lowCritical !== this.props.concept.lowCritical
|| prevProps.concept.hiAbsolute !== this.props.concept.hiAbsolute
|| prevProps.concept.lowAbsolute !== this.props.concept.lowAbsolute
) {
return true;
}
}

render() {
const { required, value } = this.props;

Expand Down

0 comments on commit 8cc6f11

Please sign in to comment.