added error input field for name and discription
This commit is contained in:
parent
d6496cb8ad
commit
b4166386a5
1 changed files with 36 additions and 11 deletions
|
@ -13,8 +13,10 @@ import androidx.compose.runtime.remember
|
|||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import be.ugent.sel.studeez.R
|
||||
import be.ugent.sel.studeez.common.composable.BasicButton
|
||||
import be.ugent.sel.studeez.common.composable.LabeledErrorTextField
|
||||
import be.ugent.sel.studeez.common.composable.LabelledInputField
|
||||
import be.ugent.sel.studeez.common.ext.basicButton
|
||||
import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo
|
||||
|
@ -28,8 +30,14 @@ abstract class AbstractTimerFormScreen(private val timerInfo: TimerInfo) {
|
|||
extraButton: @Composable () -> Unit
|
||||
) {
|
||||
|
||||
|
||||
var name by remember { mutableStateOf(timerInfo.name) }
|
||||
val isNameValid = remember { mutableStateOf(false) }
|
||||
val hasEditedName = remember { mutableStateOf(true) }
|
||||
|
||||
var description by remember { mutableStateOf(timerInfo.description) }
|
||||
val isDescriptionValid = remember { mutableStateOf(false) }
|
||||
val hasEditedDescription = remember { mutableStateOf(true) }
|
||||
|
||||
// This shall rerun whenever name and description change
|
||||
timerInfo.name = name
|
||||
|
@ -47,18 +55,30 @@ abstract class AbstractTimerFormScreen(private val timerInfo: TimerInfo) {
|
|||
) {
|
||||
|
||||
// Fields that every timer shares (ommited id)
|
||||
LabelledInputField(
|
||||
value = name,
|
||||
onNewValue = { name = it },
|
||||
LabeledErrorTextField(
|
||||
initialValue = timerInfo.name,
|
||||
label = R.string.name,
|
||||
)
|
||||
errorText = AppText.name_error,
|
||||
isValid = isNameValid,
|
||||
isFirst = hasEditedName,
|
||||
keyboardType = KeyboardType.Text,
|
||||
predicate = { it.isNotBlank() }
|
||||
) { correctName ->
|
||||
name = correctName
|
||||
}
|
||||
|
||||
LabelledInputField(
|
||||
value = description,
|
||||
onNewValue = { description = it },
|
||||
label = AppText.description,
|
||||
singleLine = false
|
||||
)
|
||||
LabeledErrorTextField(
|
||||
initialValue = timerInfo.description,
|
||||
label = R.string.description,
|
||||
errorText = AppText.description_error,
|
||||
isValid = isDescriptionValid,
|
||||
isFirst = hasEditedDescription,
|
||||
singleLine= false,
|
||||
keyboardType = KeyboardType.Text,
|
||||
predicate = { it.isNotBlank() }
|
||||
) { correctName ->
|
||||
description = correctName
|
||||
}
|
||||
|
||||
ExtraFields()
|
||||
|
||||
|
@ -66,7 +86,12 @@ abstract class AbstractTimerFormScreen(private val timerInfo: TimerInfo) {
|
|||
|
||||
Column {
|
||||
BasicButton(R.string.save, Modifier.basicButton()) {
|
||||
onSaveClick(timerInfo)
|
||||
if (isNameValid.value && isDescriptionValid.value) {
|
||||
onSaveClick(timerInfo)
|
||||
} else {
|
||||
hasEditedName.value = false
|
||||
hasEditedDescription.value = false
|
||||
}
|
||||
}
|
||||
extraButton()
|
||||
}
|
||||
|
|
Reference in a new issue