Hello everyone, I'm having an issue with an `Outli...
# compose
a
Hello everyone, I'm having an issue with an
OutlinedTextField
if I try to use it for number input only and restrict it to 2 digits after the decimal separator, see code in thread
Copy code
@Preview
@Composable
fun OutlinedTextFieldPreview() {
    var text by remember { mutableStateOf("") }

    OutlinedTextField(
        value = text,
        onValueChange = {
            var newValue = it
            if (newValue.substringAfter('.', "").length > 2) {
                newValue = newValue.dropLast(1)
            }
            text = newValue
        },
        label = { Text("Label") },
        singleLine = true,
        keyboardOptions = KeyboardOptions(
            keyboardType = KeyboardType.Number,
        ),
    )
}
If I try to enter a number like 0.1234567 it will result in output 0.1235
However if I change
keyboardType = KeyboardType.Text
then it works as expected and for the same input the output is 0.12
d
Have you tried VisualTransformation?