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
Sean McQuillan [G]
06/04/2021, 8:24 PM
You can filter in the callback and reject changes before they're applied.
Sean McQuillan [G]
06/04/2021, 8:25 PM
TextField has a pretty complicated state story for reasons - but the value passed on recomposition is considered the source of truth
👍 1
s
Steven Elliott
06/04/2021, 8:35 PM
🤔…🤦 clearly was overthinking it lol
z
Zun
06/04/2021, 10:08 PM
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
Steven Elliott
06/05/2021, 1:17 AM
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.