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(