From 16381f5896c386881ed5bcd0eb660c1f20e2e548 Mon Sep 17 00:00:00 2001 From: Jukka Ahonen Date: Wed, 13 Nov 2024 14:28:25 +0200 Subject: [PATCH] radiobuttoninline field: sort applicant type choices by value --- .../components/ApplicationSubsection.tsx | 4 ++-- src/application/helpers.ts | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/application/components/ApplicationSubsection.tsx b/src/application/components/ApplicationSubsection.tsx index 1b5ded0d9..1ec8316f2 100644 --- a/src/application/components/ApplicationSubsection.tsx +++ b/src/application/components/ApplicationSubsection.tsx @@ -17,7 +17,7 @@ import { formatDate, isFieldAllowedToRead } from "@/util/helpers"; import { ConfirmationModalTexts } from "@/enums"; import { ActionTypes, AppConsumer } from "@/app/AppContext"; import { ApplicantTypes } from "@/application/enums"; -import { getApplicationAttachmentDownloadLink, getFieldFileIds, getSectionApplicantType, getSectionTemplate, valueToApplicantType } from "@/application/helpers"; +import { getApplicationAttachmentDownloadLink, getFieldFileIds, getRadioButtonInlineFieldChoicesSorted, getSectionApplicantType, getSectionTemplate, valueToApplicantType } from "@/application/helpers"; import { getAttachmentAttributes, getAttachmentMethods, getExistingUploads, getFieldTypeMapping, getIsFetchingApplicationRelatedAttachments, getIsFetchingAttachmentAttributes, getIsFetchingPendingUploads, getIsPerformingFileOperation, getPendingUploads } from "@/application/selectors"; import { ApplicationSectionKeys } from "@/application/components/enums"; import { APPLICANT_MAIN_IDENTIFIERS, APPLICANT_SECTION_IDENTIFIER, APPLICANT_TYPE_FIELD_IDENTIFIER, EMAIL_FIELD_IDENTIFIER, TARGET_SECTION_IDENTIFIER } from "@/application/constants"; @@ -271,7 +271,7 @@ const ApplicationFormSubsectionFields = connect((state, props) => ({ type: 'radio-with-field' }; fieldOverrides = { - options: field.choices.map(choice => ({ + options: getRadioButtonInlineFieldChoicesSorted(field, field.choices).map(choice => ({ label: choice.text, value: choice.value, field: choice.has_text_input ? ) => any => (title: string, section: FormSection, answer: SavedApplicationFormSection): string => { if (section.identifier === TARGET_SECTION_IDENTIFIER && answer?.metadata?.identifier) { const target = plotSearch?.plot_search_targets.find(target => target.id === answer.metadata?.identifier); @@ -396,4 +396,11 @@ export const prepareApplicationForSubmission = (sections: Record): console.log(e); return null; } -}; \ No newline at end of file +}; + +export const getRadioButtonInlineFieldChoicesSorted = (field: FormField, choices: FormFieldChoice[]): FormFieldChoice[] => { + if (field.identifier === APPLICANT_TYPE_FIELD_IDENTIFIER) { + return choices.sort((a: FormFieldChoice, b: FormFieldChoice): number => parseInt(a.value) - parseInt(b.value) || 0); + } + return choices; +} \ No newline at end of file