From fa744239a3d8f561c2877965bf8202d3863a643c Mon Sep 17 00:00:00 2001 From: bkristmundsson Date: Wed, 22 Jan 2025 13:58:50 +0000 Subject: [PATCH] TS-949 Create language selection - Added error --- .../src/fields/LanguageSelection/index.tsx | 4 ++++ .../differentNeedsSection/languageSubSection.ts | 1 - .../templates/new-primary-school/src/lib/dataSchema.ts | 2 +- .../templates/new-primary-school/src/lib/messages.ts | 5 +++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/libs/application/templates/new-primary-school/src/fields/LanguageSelection/index.tsx b/libs/application/templates/new-primary-school/src/fields/LanguageSelection/index.tsx index 0e2d81314bb6..bd2844490b9b 100644 --- a/libs/application/templates/new-primary-school/src/fields/LanguageSelection/index.tsx +++ b/libs/application/templates/new-primary-school/src/fields/LanguageSelection/index.tsx @@ -7,6 +7,7 @@ import { SelectController } from '@island.is/shared/form-fields' import { getAllLanguageCodes } from '@island.is/shared/utils' import { newPrimarySchoolMessages } from '../../lib/messages' import { getApplicationAnswers } from '../../lib/newPrimarySchoolUtils' +import { getErrorViaPath } from '@island.is/application/core' const languagesIds = { language1: 'languages.language1', @@ -18,6 +19,7 @@ const languagesIds = { const LanguageSelection: FC> = ({ application, + errors, }) => { const { formatMessage } = useLocale() @@ -93,6 +95,7 @@ const LanguageSelection: FC> = ({ newPrimarySchoolMessages.differentNeeds.languageSelectionAriaLabel, { no: `${index + 1}` }, )} + error={errors && getErrorViaPath(errors, languageIdsArray[index])} placeholder={formatMessage( newPrimarySchoolMessages.differentNeeds .languageSelectionPlaceholder, @@ -138,6 +141,7 @@ const LanguageSelection: FC> = ({ newPrimarySchoolMessages.differentNeeds .languageSelectionPlaceholder, )} + error={errors && getErrorViaPath(errors, languagesIds.childLanguage)} id={languagesIds.childLanguage} name={languagesIds.childLanguage} backgroundColor="blue" diff --git a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/languageSubSection.ts b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/languageSubSection.ts index ea248dd32afd..66be87565249 100644 --- a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/languageSubSection.ts +++ b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/languageSubSection.ts @@ -36,7 +36,6 @@ export const languageSubSection = buildSubSection({ placeholder: newPrimarySchoolMessages.differentNeeds .languageEnvironmentPlaceholder, - required: true, options: () => { return getLanguageEnvironments() }, diff --git a/libs/application/templates/new-primary-school/src/lib/dataSchema.ts b/libs/application/templates/new-primary-school/src/lib/dataSchema.ts index 664408c6d925..120fef32e56d 100644 --- a/libs/application/templates/new-primary-school/src/lib/dataSchema.ts +++ b/libs/application/templates/new-primary-school/src/lib/dataSchema.ts @@ -169,7 +169,7 @@ export const dataSchema = z.object({ }, { path: ['childLanguage'], - params: errorMessages.languagesRequired, + params: errorMessages.languageRequired, }, ) .refine( diff --git a/libs/application/templates/new-primary-school/src/lib/messages.ts b/libs/application/templates/new-primary-school/src/lib/messages.ts index 70c413eef283..5d94b644ba66 100644 --- a/libs/application/templates/new-primary-school/src/lib/messages.ts +++ b/libs/application/templates/new-primary-school/src/lib/messages.ts @@ -828,6 +828,11 @@ export const errorMessages = defineMessages({ defaultMessage: 'Það þarf að velja a.m.k eitt tungumál', description: 'At least one language must be selected', }, + languageRequired: { + id: 'nps.application:error.language.required', + defaultMessage: 'Það þarf að velja tungumál', + description: 'Language must be selected', + }, noChildrenFoundTitle: { id: 'nps.application:error.no.children.found.title', defaultMessage: 'Því miður ert þú ekki með skráð barn á grunnskólaaldri',