|
1 | 1 | /* |
2 | | - * Copyright 2023-2024 Google LLC |
| 2 | + * Copyright 2023-2025 Google LLC |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
@@ -298,12 +298,6 @@ internal class QuestionnaireViewModel(application: Application, state: SavedStat |
298 | 298 |
|
299 | 299 | private lateinit var currentPageItems: List<QuestionnaireAdapterItem> |
300 | 300 |
|
301 | | - /** |
302 | | - * True if the user has tapped the next/previous pagination buttons on the current page. This is |
303 | | - * needed to avoid spewing validation errors before any questions are answered. |
304 | | - */ |
305 | | - private var forceValidation = false |
306 | | - |
307 | 301 | /** |
308 | 302 | * Map of [QuestionnaireResponseItemAnswerComponent] for |
309 | 303 | * [Questionnaire.QuestionnaireItemComponent]s that are disabled now. The answers will be used to |
@@ -903,7 +897,6 @@ internal class QuestionnaireViewModel(application: Application, state: SavedStat |
903 | 897 | val validationResult = |
904 | 898 | if ( |
905 | 899 | modifiedQuestionnaireResponseItemSet.contains(questionnaireResponseItem) || |
906 | | - forceValidation || |
907 | 900 | isInReviewModeFlow.value |
908 | 901 | ) { |
909 | 902 | questionnaireResponseItemValidator.validate( |
@@ -1124,13 +1117,14 @@ internal class QuestionnaireViewModel(application: Application, state: SavedStat |
1124 | 1117 | it.item.validationResult is NotValidated |
1125 | 1118 | } |
1126 | 1119 | ) { |
1127 | | - // Force update validation results for all questions on the current page. This is needed |
1128 | | - // when the user has not answered any questions so no validation has been done. |
1129 | | - forceValidation = true |
| 1120 | + // Add all items on the current page to modifiedQuestionnaireResponseItemSet. |
| 1121 | + // This will ensure that all fields are validated even when they're not filled by the user |
| 1122 | + currentPageItems.filterIsInstance<QuestionnaireAdapterItem.Question>().forEach { |
| 1123 | + modifiedQuestionnaireResponseItemSet.add(it.item.getQuestionnaireResponseItem()) |
| 1124 | + } |
1130 | 1125 | // Results in a new questionnaire state being generated synchronously, i.e., the current |
1131 | 1126 | // thread will be suspended until the new state is generated. |
1132 | 1127 | modificationCount.update { it + 1 } |
1133 | | - forceValidation = false |
1134 | 1128 | } |
1135 | 1129 |
|
1136 | 1130 | if ( |
|
0 commit comments