Is there something akin to `.replace` that works o...
# compose
f
Is there something akin to
.replace
that works on
TextFieldValue
(takes cursor / selection into account)? I'm trying to have forbidden characters (like @) in my
TextField
so I'm just doing
.replace("@", "")
inside
onValueChange
but this means the cursor will stay on the position of the removed character (i.e. behaves like "insert" key is on). I feel this is simple to solve, but just wanted to check if there's some builtin method I'm missing.
o
I guess you want to check the
VisualTransformation
and
OffsetMapping
https://developer.android.com/reference/kotlin/androidx/compose/ui/text/input/VisualTransformation
f
This wouldn't change the value though - just what the use sees. I want to ensure the invalid character(s) never reach my DB / backend.
o
Then I would pre-process the user’s input before it is persisted or send.
f
That's sort of what I'm doing - but then either I display the processed input (which is the issue I'm having, cursor position might end up wrong) or I show something different to the user
s
cursor position is TextFieldValue.selection = TextRange(myPosition)