Hello Everyone, I'm stuck with textfield issue, ba...
# compose
m
Hello Everyone, I'm stuck with textfield issue, basically its a phone number textfield which basically gets formatted from viewmodel. If i'm using textfieldvalue due to its selection properties it does not allow to move the cursor. if i'm using string then after formatted from viewmodel, cursor not moving to end of the textfield value.
z
You’re gonna have to elaborate, sorry
m
Elaborated now please check now.
z
If i'm using textfieldvalue due to its selection properties it does not allow to move the cursor.
Not sure I understand this part. The value passed to the callback is a TextFieldValue. The cursor should respect whatever TextFieldValue you pass back in. If it doesn’t, that’s a bug.
m
Do you now how to achieve this, if textfield value changes move the cursor to end of the textfield and also let the user to move the cursor by dragging it left or right?
z
When the user drags the cursor, that should invoke the callback, which should let you change your state.
m
Sorry i didn't get you
if your using TextFieldValue( number, selection = TextRange(number.length) ) this is not allowing to drag.
z
You need to update your selection from the text fields callback. When the selection is dragged, the callback will be invoked with the new selection.
m
Okay
Can you provide some sorts of example if possible?
z
Copy code
var textFieldValue by remember { mutableStateOf(TextFieldValue(number, selection = number.length) }
TextField(textFieldValue, onValueChange = { textFieldValue = it })
m
Thanks @Zach Klippenstein (he/him) [MOD]