-
Notifications
You must be signed in to change notification settings - Fork 305
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
9dda845
9bf3bb7
d3292f2
f0fde4b
45d4416
33232fb
38e0b03
9f545cc
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 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what happens when the minValue is bigger than the maxValue? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the exception. UI will crash when minValue > maxValue, like the slider and date widgets. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, but feel free to speak your thoughts on this, we could for example: show an error message to the user, instead of outright crashing the app. We're open for discussion. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ig it's rare for a scenario like that to happen. Adheres to the rules, but with nonsensical values. Alternatively, I view the minValue > maxValue a meaningless constraint on the UI, so it make sense to treat it as though the constraint doesn’t exist? We can set Looks like the web app https://lhcforms.nlm.nih.gov/lhcforms ignored that scenario |
||
// 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
bind
function is not necessary,updateValidationTextUI
function is already called in the parent'sbind
(you can check it), so throwing the error inupdateValidationTextUI
should suffice.What do you think?
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 extendingQuestionnaireItemViewHolder
android-fhir/datacapture/src/main/java/com/google/android/fhir/datacapture/views/factories/QuestionnaireItemViewHolderFactory.kt
Lines 67 to 73 in ecf949a