When using a text field is there a way to prevent ...
# compose
s
When using a text field is there a way to prevent the composable from triggering the onValueChange callback? For example let's say I only want the text field to allow numerical input.
s
You can filter in the callback and reject changes before they're applied.
TextField has a pretty complicated state story for reasons - but the value passed on recomposition is considered the source of truth
👍 1
s
🤔🤦 clearly was overthinking it lol
z
Wouldn’t it make more sense to set the keyboardOptions? I’m unsure if this prevents certain characters when using a physical keyboard or when pasting text into it
s
I did look into that route by providing a KeyboardOption with the type set to number. However that still allows any character as it does not prevent character input from a physical keyboard or pasting text.