fix: 漏加的限制
This commit is contained in:
parent
0f5532de8a
commit
4db78310f9
3 changed files with 15 additions and 10 deletions
|
|
@ -205,6 +205,15 @@ fun TodoEditorPage(
|
||||||
value = uiState.categoryContent,
|
value = uiState.categoryContent,
|
||||||
onValueChange = { uiState.categoryContent = it },
|
onValueChange = { uiState.categoryContent = it },
|
||||||
isError = uiState.isErrorCategory,
|
isError = uiState.isErrorCategory,
|
||||||
|
supportingText = when {
|
||||||
|
uiState.categoryContent.trim().isEmpty() ->
|
||||||
|
stringResource(R.string.error_no_content_entered)
|
||||||
|
|
||||||
|
uiState.categoryContent.length > 5 ->
|
||||||
|
stringResource(R.string.error_exceeds_5_chars)
|
||||||
|
|
||||||
|
else -> stringResource(R.string.tip_max_length_5)
|
||||||
|
},
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
/*.sharedBounds(
|
/*.sharedBounds(
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ fun TodoCategoryTextField(
|
||||||
value: String,
|
value: String,
|
||||||
onValueChange: (String) -> Unit,
|
onValueChange: (String) -> Unit,
|
||||||
isError: Boolean,
|
isError: Boolean,
|
||||||
|
supportingText: String = stringResource(R.string.tip_max_length_5),
|
||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
TextField(
|
TextField(
|
||||||
|
|
@ -49,15 +50,8 @@ fun TodoCategoryTextField(
|
||||||
onValueChange = onValueChange,
|
onValueChange = onValueChange,
|
||||||
label = { Text(stringResource(R.string.label_enter_category_name)) },
|
label = { Text(stringResource(R.string.label_enter_category_name)) },
|
||||||
isError = isError,
|
isError = isError,
|
||||||
supportingText = {
|
supportingText = { Text(supportingText) },
|
||||||
AnimatedVisibility(
|
maxLines = 1,
|
||||||
visible = isError,
|
|
||||||
enter = fadeIn() + expandVertically(),
|
|
||||||
exit = fadeOut() + shrinkVertically()
|
|
||||||
) {
|
|
||||||
Text(stringResource(R.string.error_no_content_entered))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -29,7 +29,9 @@ class EditorState(val initialTodo: TodoEntity? = null) {
|
||||||
*/
|
*/
|
||||||
fun setErrorIfNotValid(): Boolean {
|
fun setErrorIfNotValid(): Boolean {
|
||||||
isErrorContent = toDoContent.trim().isEmpty()
|
isErrorContent = toDoContent.trim().isEmpty()
|
||||||
isErrorCategory = if (selectedCategoryIndex == -1) categoryContent.trim().isEmpty() else false
|
isErrorCategory = if (selectedCategoryIndex == -1) {
|
||||||
|
categoryContent.trim().isEmpty() || categoryContent.trim().length > 5
|
||||||
|
} else false
|
||||||
return isErrorContent || isErrorCategory
|
return isErrorContent || isErrorCategory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue