I am working on a process where when users want to change password, they are able to do that within a current password, new password, retypenewpassword flow. My challenge however has been with using my reusable outlined text field to handle the error. For example if the users enters an old password and it is wrong it shows below the outlinedTextField that wrong password was entered. Like the image I have attached
The challenge I experienced with Jetpack Compose is on the isError,
for all 3 since I am using one but customizing output for each. I can not add my condition there to validate the error
. Or maybe I am approaching this the wrong way. Here is my composable.
@Composable
fun UserInputTextField(
fieldState: String,
onFieldChange: (String) -> Unit,
label: String,
isError: Boolean = false
modifier: Modifier = Modifier,
) {
androidx.compose.material.OutlinedTextField(
value = fieldState, onValueChange = {
onFieldChange(it)
},
isError = isError
label = { androidx.compose.material.Text(text = label) },
modifier = modifier
.fillMaxWidth()
.padding(top = 16.dp)
,
colors = TextFieldDefaults.outlinedTextFieldColors(
focusedBorderColor = Color.Blue,
unfocusedBorderColor = Color.Black
)
)
}
Now when I call my reusable, I want for all my three OutlinedEditText when there is an error display something like the image
My problem is, how can I display an error on all 3 UserInputTextField
using the isError since the message has to be under the OutlinedTextField.
UserInputTextField(
fieldState = usernameState.value,
onFieldChange = { usernameState.value = it },
label = "Enter Name",
isError = if(state.usernameState.isValidPassword)... do something else print error?
)