Skip to content

Commit

Permalink
In FractionInteraction UI, leave submit button enabled when answer is…
Browse files Browse the repository at this point in the history
… empty. Show an error on submitting an empty answer.
  • Loading branch information
masclot committed Oct 17, 2023
1 parent e060e2f commit 52e1261
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ class FractionInteractionViewModel private constructor(
override fun onPropertyChanged(sender: Observable, propertyId: Int) {
errorOrAvailabilityCheckReceiver.onPendingAnswerErrorOrAvailabilityCheck(
pendingAnswerError,
answerText.isNotEmpty()
true // Allow submit on empty answer
)
}
}
errorMessage.addOnPropertyChangedCallback(callback)
isAnswerAvailable.addOnPropertyChangedCallback(callback)
// Apply defaults:
errorOrAvailabilityCheckReceiver.onPendingAnswerErrorOrAvailabilityCheck(
null,
true
)
}

override fun getPendingAnswer(): UserAnswer = UserAnswer.newBuilder().apply {
Expand All @@ -64,23 +69,28 @@ class FractionInteractionViewModel private constructor(

/** It checks the pending error for the current fraction input, and correspondingly updates the error string based on the specified error category. */
override fun checkPendingAnswerError(category: AnswerErrorCategory): String? {
if (answerText.isNotEmpty()) {
when (category) {
AnswerErrorCategory.REAL_TIME -> {
when (category) {
AnswerErrorCategory.REAL_TIME -> {
if (answerText.isNotEmpty()) {
pendingAnswerError =
FractionParsingUiError.createFromParsingError(
fractionParser.getRealTimeAnswerError(answerText.toString())
).getErrorMessageFromStringRes(resourceHandler)
} else {
pendingAnswerError = null
}
AnswerErrorCategory.SUBMIT_TIME -> {
pendingAnswerError =
FractionParsingUiError.createFromParsingError(
fractionParser.getSubmitTimeError(answerText.toString())
).getErrorMessageFromStringRes(resourceHandler)
}
AnswerErrorCategory.SUBMIT_TIME -> {
pendingAnswerError = if (answerText.isNotEmpty()) {
FractionParsingUiError.createFromParsingError(
fractionParser.getSubmitTimeError(answerText.toString())
).getErrorMessageFromStringRes(resourceHandler)
} else {
resourceHandler.getStringInLocale(R.string.interaction_answer_empty_on_submit)
}
}
errorMessage.set(pendingAnswerError)
}
errorMessage.set(pendingAnswerError)
return pendingAnswerError
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -606,4 +606,5 @@
<string name="lock_icon_content_description">Lock Icon</string>
<string name="download_status_image_content_description">Download Status</string>
<string name="font_scale_html_content_text">html Content</string>
<string name="interaction_answer_empty_on_submit">"Enter an answer to continue"</string>
</resources>

0 comments on commit 52e1261

Please sign in to comment.