diff --git a/app/src/main/java/org/dhis2/usescases/searchTrackEntity/SearchTEActivity.java b/app/src/main/java/org/dhis2/usescases/searchTrackEntity/SearchTEActivity.java index 579cd99d6a..4969166fcf 100644 --- a/app/src/main/java/org/dhis2/usescases/searchTrackEntity/SearchTEActivity.java +++ b/app/src/main/java/org/dhis2/usescases/searchTrackEntity/SearchTEActivity.java @@ -363,7 +363,8 @@ private void initSearchParameters() { uid, selectedOrgUnit, ValueType.ORGANISATION_UNIT, - null + null, + true ) ); return Unit.INSTANCE; diff --git a/form/src/main/java/org/dhis2/form/ui/FormViewModel.kt b/form/src/main/java/org/dhis2/form/ui/FormViewModel.kt index 4f77acb803..4665261e09 100644 --- a/form/src/main/java/org/dhis2/form/ui/FormViewModel.kt +++ b/form/src/main/java/org/dhis2/form/ui/FormViewModel.kt @@ -398,6 +398,7 @@ class FormViewModel( intent.valueType, intent.value, intent.fieldMask, + intent.allowFutureDates, ) createRowAction( @@ -586,7 +587,7 @@ class FormViewModel( try { val date = LocalDate.parse(dateString, formatter) if (allowFutureDates == false && date.isAfter(LocalDate.now())) { - return Result.Failure(DateFailure.ParseException) + return Result.Failure(Throwable()) } return valueType.validator.validate(dateString) } catch (e: DateTimeParseException) { diff --git a/form/src/main/java/org/dhis2/form/ui/intent/FormIntent.kt b/form/src/main/java/org/dhis2/form/ui/intent/FormIntent.kt index b6a7863825..1f37d3b459 100644 --- a/form/src/main/java/org/dhis2/form/ui/intent/FormIntent.kt +++ b/form/src/main/java/org/dhis2/form/ui/intent/FormIntent.kt @@ -24,6 +24,7 @@ sealed class FormIntent { val value: String?, val valueType: ValueType?, val fieldMask: String? = null, + val allowFutureDates: Boolean? = false, ) : FormIntent() data class OnQrCodeScanned( @@ -42,7 +43,6 @@ sealed class FormIntent { val uid: String, val value: String?, val valueType: ValueType?, - val allowFutureDates: Boolean? = false, ) : FormIntent() data class ClearValue( diff --git a/form/src/main/java/org/dhis2/form/ui/provider/inputfield/AgeProvider.kt b/form/src/main/java/org/dhis2/form/ui/provider/inputfield/AgeProvider.kt index 78d23930f2..a013ab1125 100644 --- a/form/src/main/java/org/dhis2/form/ui/provider/inputfield/AgeProvider.kt +++ b/form/src/main/java/org/dhis2/form/ui/provider/inputfield/AgeProvider.kt @@ -102,13 +102,17 @@ fun ProvideInputAge( } is AgeInputType.DateOfBirth -> { - saveValue( - intentHandler, - fieldUiModel.uid, - formatUIDateToStored(type.value.text), - fieldUiModel.valueType, - fieldUiModel.allowFutureDates, - ) + formatUIDateToStored(type.value.text) + .takeIf { it != fieldUiModel.value } + ?.let { + saveValue( + intentHandler, + fieldUiModel.uid, + it, + fieldUiModel.valueType, + fieldUiModel.allowFutureDates, + ) + } } AgeInputType.None -> { @@ -135,14 +139,23 @@ private fun saveValue( valueType: ValueType?, allowFutureDates: Boolean?, ) { - intentHandler.invoke( - FormIntent.OnTextChange( - uid, - value, - valueType, - allowFutureDates ?: false, - ), - ) + when (value?.length) { + null, 10 -> intentHandler.invoke( + FormIntent.OnSave( + uid, + value, + valueType, + allowFutureDates = allowFutureDates, + ), + ) + else -> intentHandler.invoke( + FormIntent.OnTextChange( + uid, + value, + valueType, + ), + ) + } } private fun formatStoredDateToUI(inputDateString: String): String { diff --git a/form/src/main/java/org/dhis2/form/ui/provider/inputfield/DateProvider.kt b/form/src/main/java/org/dhis2/form/ui/provider/inputfield/DateProvider.kt index 8301f6d1f4..48a9d8c7d4 100644 --- a/form/src/main/java/org/dhis2/form/ui/provider/inputfield/DateProvider.kt +++ b/form/src/main/java/org/dhis2/form/ui/provider/inputfield/DateProvider.kt @@ -69,14 +69,21 @@ fun ProvideInputDate( onNextClicked = onNextClicked, onValueChanged = { value = it ?: TextFieldValue() - intentHandler.invoke( + val formIntent = if (value.text.length == 8) { + FormIntent.OnSave( + uid = fieldUiModel.uid, + value = formatUIDateToStored(it?.text, fieldUiModel.valueType), + valueType = fieldUiModel.valueType, + allowFutureDates = fieldUiModel.allowFutureDates, + ) + } else { FormIntent.OnTextChange( uid = fieldUiModel.uid, value = formatUIDateToStored(it?.text, fieldUiModel.valueType), valueType = fieldUiModel.valueType, - allowFutureDates = fieldUiModel.allowFutureDates ?: true, - ), - ) + ) + } + intentHandler.invoke(formIntent) }, selectableDates = selectableDates, yearRange = yearIntRange, diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index feffbf2e03..3ebb7af3ed 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -10,7 +10,7 @@ kotlin = '1.9.21' hilt = '2.47' hiltCompiler = '1.0.0' jacoco = '0.8.10' -designSystem = "0.2" +designSystem = "0.2-SNAPSHOT" dhis2sdk = "1.10.0.1" ruleEngine = "3.0.0" expressionParser = "1.1.0"