Skip to content

Commit

Permalink
fix: make program attribute mandatory if TET attribute is mandatory
Browse files Browse the repository at this point in the history
  • Loading branch information
superskip committed Oct 31, 2023
1 parent 5457c90 commit 6085fd5
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import { useMemo } from 'react';
import { useOptionSetsForAttributes } from './hooks/useOptionSetsForAttributes';
import { scopeTypes } from '../../../../../metaData';
import { scopeTypes, Section } from '../../../../../metaData';
import { useProgramFromIndexedDB } from '../../../../../utils/cachedDataHooks/useProgramFromIndexedDB';
import { useScopeInfo } from '../../../../../hooks/useScopeInfo';
import { useTrackedEntityTypeCollection } from './hooks/useTrackedEntityTypeCollection';
Expand Down Expand Up @@ -72,6 +72,18 @@ export const useMetadataForRegistrationForm = ({ selectedScopeId }: Props) => {
locale,
});

if (trackedEntityType && enrollment) {
for (const tetAttribute of trackedEntityType.trackedEntityTypeAttributes) {
if (tetAttribute.mandatory) {
const enrollmentAttribute = enrollment.enrollmentForm.getSection(Section.MAIN_SECTION_ID).elements
.get(tetAttribute.trackedEntityAttributeId);
if (enrollmentAttribute) {
enrollmentAttribute.compulsory = true;
}
}
}
}

if (scopeType === scopeTypes.TRACKED_ENTITY_TYPE && trackedEntityTypeCollection && tetId) {
return {
name: trackedEntityTypeCollection.name,
Expand Down

0 comments on commit 6085fd5

Please sign in to comment.