Skip to content

Commit

Permalink
added checks for empty
Browse files Browse the repository at this point in the history
  • Loading branch information
aman-alfresco committed Jan 5, 2024
1 parent 12d9bb7 commit db55410
Showing 1 changed file with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,21 @@ fun AmountInputFieldPreview() {
fun isValidInput(inputText: String?, fieldsData: FieldsData): Pair<Boolean, String> {
val errorData = Pair(false, "")

if (!inputText.isNullOrEmpty()) {
if (inputText.isNullOrEmpty()) {
return errorData
}

inputText?.apply {
if (this.toFloat() < (fieldsData.minValue?.toFloat() ?: 0f)) {
return Pair(true, stringResource(R.string.error_min_value, fieldsData.minLength))
}
if (inputText.toFloat() < (fieldsData.minValue?.toFloat() ?: 0f)) {
return Pair(true, stringResource(R.string.error_min_value, fieldsData.minLength))
}

if (this.toFloat() > (fieldsData.minValue?.toFloat() ?: 0f)) {
return Pair(true, stringResource(R.string.error_max_value, fieldsData.minLength))
}
if (inputText.toFloat() > (fieldsData.minValue?.toFloat() ?: 0f)) {
return Pair(true, stringResource(R.string.error_max_value, fieldsData.minLength))
}

if (fieldsData.enableFractions) {
if (this.toFloatOrNull() != null) {
return Pair(true, stringResource(R.string.error_invalid_format))
}
if (fieldsData.enableFractions) {
if (inputText.toFloatOrNull() != null) {
return Pair(true, stringResource(R.string.error_invalid_format))
}
}

Expand Down

0 comments on commit db55410

Please sign in to comment.