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 4 commits into
base: master
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Expand Down Expand Up @@ -38,6 +38,7 @@ internal object EditTextIntegerViewHolderFactory :
QuestionnaireItemEditTextViewHolderDelegate(
InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_SIGNED,
) {

override suspend fun handleInput(
editable: Editable,
questionnaireViewItem: QuestionnaireViewItem,
Expand Down Expand Up @@ -90,13 +91,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

Comment on lines +105 to +110
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens when the minValue is bigger than the maxValue?
how about we throw an exception when that happens?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator

@FikriMilano FikriMilano Jan 21, 2025

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 minAnswerValue and maxAnswerValue to null if when that happens.

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),
)
}
}
Expand Down