From 8d9f566aa2400dab6689368f971a2ec5313482c3 Mon Sep 17 00:00:00 2001 From: Magnus Brecke Date: Tue, 20 Aug 2024 20:27:12 +0200 Subject: [PATCH] Fix bug in application validation Filter out groups that are not a part of this application --- frontend/src/routes/ApplicationForm/index.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/frontend/src/routes/ApplicationForm/index.tsx b/frontend/src/routes/ApplicationForm/index.tsx index 5e4ca1dd..9405b379 100644 --- a/frontend/src/routes/ApplicationForm/index.tsx +++ b/frontend/src/routes/ApplicationForm/index.tsx @@ -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", )), ); @@ -156,7 +160,11 @@ const ApplicationForm: React.FC = ({ 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]; });