From e7dd44cb66f0dc5c19201484c32eb3f23693ce7a Mon Sep 17 00:00:00 2001 From: Pablo Pajuelo Cabezas Date: Tue, 17 Dec 2024 14:38:55 +0100 Subject: [PATCH] fix: crash when checking multi selection input --- .../provider/inputfield/MultiSelectionInputProvider.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/form/src/main/java/org/dhis2/form/ui/provider/inputfield/MultiSelectionInputProvider.kt b/form/src/main/java/org/dhis2/form/ui/provider/inputfield/MultiSelectionInputProvider.kt index 976fda619d..245606bcf0 100644 --- a/form/src/main/java/org/dhis2/form/ui/provider/inputfield/MultiSelectionInputProvider.kt +++ b/form/src/main/java/org/dhis2/form/ui/provider/inputfield/MultiSelectionInputProvider.kt @@ -45,9 +45,13 @@ internal fun ProvideMultiSelectionInput( legendData = fieldUiModel.legend(), isRequired = fieldUiModel.mandatory, onItemsSelected = { - val checkedValues = it.filter { item -> item.checked }.map { checkBoxData -> - val selectedIndex = data.indexOf(checkBoxData) - codeList[selectedIndex] + val checkedValues = it.mapNotNull { checkBoxData -> + if (checkBoxData.checked) { + val selectedIndex = data.indexOfFirst { originalData -> originalData.uid == checkBoxData.uid } + codeList[selectedIndex] + } else { + null + } } intentHandler(