Hi, anyone who would know what's wrong in follow...
# compose-desktop
j
Hi, anyone who would know what's wrong in following example with OutlinedTextField ?
I have this following example to simply filter out typing just for digits.
Copy code
@Composable
fun Test2() {
    Column {
        var text by remember { mutableStateOf("") }
        OutlinedTextField(value = text,
            onValueChange = { v ->
                println("OTF:$v")
                if (v.isEmpty() || v.toIntOrNull() != null) {
                    text = v
                }
            })
        TextField(value = text,
            onValueChange = { v ->
                println(v)
                if (v.isEmpty() || v.toIntOrNull() != null) {
                    text = v
                }
            })
    }
}
However if I try to start typing for example "-abcd1234", then I'd expect to ignore "-abcd" and just type into it "1234" and that's not happening. printlns:
Copy code
OTF:-
OTF:-a
OTF:-ab
OTF:-abc
OTF:-abcd
OTF:-abcde
OTF:-abcde1
OTF:-abcde12
OTF:-abcde123
OTF:-abcde1234
Trying to do same thing with the TextField just works as expected. What am I missing here ?
t
I'm not sure what is causing that issue, but I would do
text = v.filter { it in '0'..'9' }
to avoid the branch
(
Char.isDigit
would also work but Java has a wild definition of "digit"... :))