-
Notifications
You must be signed in to change notification settings - Fork 329
Include min and max values in the validation message in a number question if the values are in the extension #2763
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
9dda845
9bf3bb7
d3292f2
f0fde4b
45d4416
33232fb
38e0b03
9f545cc
97f685c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * Copyright 2022-2024 Google LLC | ||
| * Copyright 2022-2025 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
|
|
@@ -38,6 +38,18 @@ internal object EditTextIntegerViewHolderFactory : | |
| QuestionnaireItemEditTextViewHolderDelegate( | ||
| InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_SIGNED, | ||
| ) { | ||
|
|
||
| override fun bind(questionnaireViewItem: QuestionnaireViewItem) { | ||
| super.bind(questionnaireViewItem) | ||
|
|
||
| val minValue = (questionnaireViewItem.minAnswerValue as? IntegerType)?.value | ||
| val maxValue = (questionnaireViewItem.maxAnswerValue as? IntegerType)?.value | ||
|
|
||
| if (minValue != null && maxValue != null && minValue > maxValue) { | ||
| throw IllegalArgumentException("minValue cannot be greater than maxValue") | ||
| } | ||
| } | ||
|
|
||
| override suspend fun handleInput( | ||
| editable: Editable, | ||
| questionnaireViewItem: QuestionnaireViewItem, | ||
|
|
@@ -90,13 +102,19 @@ internal object EditTextIntegerViewHolderFactory : | |
| questionnaireViewItem, | ||
| questionnaireViewItem.validationResult, | ||
| ) | ||
|
|
||
| val minValue = | ||
| (questionnaireViewItem.minAnswerValue as? IntegerType)?.value ?: Int.MIN_VALUE | ||
| val maxValue = | ||
| (questionnaireViewItem.maxAnswerValue as? IntegerType)?.value ?: Int.MAX_VALUE | ||
|
|
||
|
||
| // Update error message if draft answer present | ||
| if (questionnaireViewItem.draftAnswer != null) { | ||
| textInputLayout.error = | ||
| textInputLayout.context.getString( | ||
| R.string.integer_format_validation_error_msg, | ||
| formatInteger(Int.MIN_VALUE), | ||
| formatInteger(Int.MAX_VALUE), | ||
| formatInteger(minValue), | ||
| formatInteger(maxValue), | ||
| ) | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel overriding the
bindfunction is not necessary,updateValidationTextUIfunction is already called in the parent'sbind(you can check it), so throwing the error inupdateValidationTextUIshould suffice.What do you think?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had it that way initially, but i thought placing the constraint check didn’t fit the intent of the function name
updateValidationTextUI, so I moved it tobind. Like jingtang10 commented, it would be better to have it in the view model to remove redundancymaybe have it in
QuestionnaireItemViewHolder, I believe all the factories are extendingQuestionnaireItemViewHolderhttps://github.com/google/android-fhir/blob/ecf949a79cca940500727510c29adc619ce6a253/datacapture/src/main/java/com/google/android/fhir/datacapture/views/factories/QuestionnaireItemViewHolderFactory.kt#L67-L73