Skip to content

Commit

Permalink
TS-949 Create language selection
Browse files Browse the repository at this point in the history
- Added error
  • Loading branch information
birkirkristmunds committed Jan 22, 2025
1 parent 183a7ed commit fa74423
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -18,6 +19,7 @@ const languagesIds = {

const LanguageSelection: FC<React.PropsWithChildren<FieldBaseProps>> = ({
application,
errors,
}) => {
const { formatMessage } = useLocale()

Expand Down Expand Up @@ -93,6 +95,7 @@ const LanguageSelection: FC<React.PropsWithChildren<FieldBaseProps>> = ({
newPrimarySchoolMessages.differentNeeds.languageSelectionAriaLabel,
{ no: `${index + 1}` },
)}
error={errors && getErrorViaPath(errors, languageIdsArray[index])}
placeholder={formatMessage(
newPrimarySchoolMessages.differentNeeds
.languageSelectionPlaceholder,
Expand Down Expand Up @@ -138,6 +141,7 @@ const LanguageSelection: FC<React.PropsWithChildren<FieldBaseProps>> = ({
newPrimarySchoolMessages.differentNeeds
.languageSelectionPlaceholder,
)}
error={errors && getErrorViaPath(errors, languagesIds.childLanguage)}
id={languagesIds.childLanguage}
name={languagesIds.childLanguage}
backgroundColor="blue"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const languageSubSection = buildSubSection({
placeholder:
newPrimarySchoolMessages.differentNeeds
.languageEnvironmentPlaceholder,
required: true,
options: () => {
return getLanguageEnvironments()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export const dataSchema = z.object({
},
{
path: ['childLanguage'],
params: errorMessages.languagesRequired,
params: errorMessages.languageRequired,
},
)
.refine(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit fa74423

Please sign in to comment.