Skip to content

Commit

Permalink
Fix bug in application validation
Browse files Browse the repository at this point in the history
Filter out groups that are not a part of this application
  • Loading branch information
Magnus Brecke committed Aug 20, 2024
1 parent 1caf5d1 commit 8d9f566
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions frontend/src/routes/ApplicationForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,14 @@ const validationSchema = (
// Iterate over all selected groups and add them to the required schema
const selectedGroupsSchema: { [x: string]: Yup.StringSchema } = {};
Object.entries(selectedGroups)
.filter(([, isSelected]) => isSelected)
.filter(
([groupName, isSelected]) =>
isSelected &&
admission?.groups.some((group) => group.name === groupName),
)
.forEach(
([name]) =>
(selectedGroupsSchema[name] = Yup.string().required(
([groupName]) =>
(selectedGroupsSchema[groupName] = Yup.string().required(
"Søknadsteksten må fylles ut",
)),
);
Expand Down Expand Up @@ -156,7 +160,11 @@ const ApplicationForm: React.FC<ApplicationFormProps> = ({
header_fields_response: values.headerFields,
};
Object.keys(values.groups)
.filter((group) => selectedGroups[group])
.filter(
(groupName) =>
selectedGroups[groupName] &&
admission?.groups.some((group) => group.name === groupName),
)
.forEach((name) => {
submission.applications[name] = values.groups[name];
});
Expand Down

0 comments on commit 8d9f566

Please sign in to comment.