Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include min and max values in the validation message in a number question if the values are in the extension #2763

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import android.text.InputType
import androidx.annotation.RequiresApi
import com.google.android.fhir.datacapture.R
import com.google.android.fhir.datacapture.extensions.getValidationErrorMessage
import com.google.android.fhir.datacapture.validation.MAX_VALUE_EXTENSION_URL
import com.google.android.fhir.datacapture.validation.MIN_VALUE_EXTENSION_URL
import com.google.android.fhir.datacapture.views.QuestionnaireViewItem
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
Expand All @@ -38,6 +40,22 @@ internal object EditTextIntegerViewHolderFactory :
QuestionnaireItemEditTextViewHolderDelegate(
InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_SIGNED,
) {

private val minValue: Int by lazy {
getExtensionValueOrDefault(MIN_VALUE_EXTENSION_URL, Int.MIN_VALUE)
}

private val maxValue: Int by lazy {
getExtensionValueOrDefault(MAX_VALUE_EXTENSION_URL, Int.MAX_VALUE)
}

private fun getExtensionValueOrDefault(url: String, defaultValue: Int): Int {
return questionnaireViewItem.questionnaireItem.extension
.find { it.url == url }
?.let { (it.value as? IntegerType)?.value }
?: defaultValue
}

chungwwei marked this conversation as resolved.
Show resolved Hide resolved
override suspend fun handleInput(
editable: Editable,
questionnaireViewItem: QuestionnaireViewItem,
Expand Down Expand Up @@ -95,8 +113,8 @@ internal object EditTextIntegerViewHolderFactory :
textInputLayout.error =
textInputLayout.context.getString(
R.string.integer_format_validation_error_msg,
formatInteger(Int.MIN_VALUE),
formatInteger(Int.MAX_VALUE),
formatInteger(minValue),
formatInteger(maxValue),
)
}
}
Expand Down