Skip to content

Commit

Permalink
Fix validation message for number fields to consider min and max values
Browse files Browse the repository at this point in the history
Update validation messages for number fields to consider min and max values from the questionnaire item.

* Modify `EditTextDecimalViewHolderFactory.kt` to include min and max values in the validation message for decimal fields.
* Modify `EditTextIntegerViewHolderFactory.kt` to include min and max values in the validation message for integer fields.
  • Loading branch information
harshitIIITD committed Jan 14, 2025
1 parent 2a7e91f commit 928386e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,14 @@ internal object EditTextDecimalViewHolderFactory :
)
// Update error message if draft answer present
if (questionnaireViewItem.draftAnswer != null) {
val minValue = questionnaireViewItem.minAnswerValue?.toString() ?: DecimalType(Int.MIN_VALUE).toString()
val maxValue = questionnaireViewItem.maxAnswerValue?.toString() ?: DecimalType(Int.MAX_VALUE).toString()
textInputLayout.error =
textInputLayout.context.getString(R.string.decimal_format_validation_error_msg)
textInputLayout.context.getString(
R.string.decimal_format_validation_error_msg,
minValue,
maxValue
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ internal object EditTextIntegerViewHolderFactory :
)
// Update error message if draft answer present
if (questionnaireViewItem.draftAnswer != null) {
val minValue = questionnaireViewItem.minAnswerValue?.toString() ?: IntegerType(Int.MIN_VALUE).toString()
val maxValue = questionnaireViewItem.maxAnswerValue?.toString() ?: IntegerType(Int.MAX_VALUE).toString()
textInputLayout.error =
textInputLayout.context.getString(
R.string.integer_format_validation_error_msg,
formatInteger(Int.MIN_VALUE),
formatInteger(Int.MAX_VALUE),
minValue,
maxValue
)
}
}
Expand Down

0 comments on commit 928386e

Please sign in to comment.