https://kotlinlang.org logo
#compose
Title
# compose
m

Mahendra Sutar

12/15/2023, 6:01 AM
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

Zach Klippenstein (he/him) [MOD]

12/15/2023, 6:03 AM
You’re gonna have to elaborate, sorry
m

Mahendra Sutar

12/15/2023, 6:04 AM
Elaborated now please check now.
z

Zach Klippenstein (he/him) [MOD]

12/15/2023, 6:12 AM
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

Mahendra Sutar

12/15/2023, 6:19 AM
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

Zach Klippenstein (he/him) [MOD]

12/15/2023, 6:22 AM
When the user drags the cursor, that should invoke the callback, which should let you change your state.
m

Mahendra Sutar

12/15/2023, 6:26 AM
Sorry i didn't get you
if your using TextFieldValue( number, selection = TextRange(number.length) ) this is not allowing to drag.
z

Zach Klippenstein (he/him) [MOD]

12/15/2023, 6:30 AM
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

Mahendra Sutar

12/15/2023, 6:30 AM
Okay
Can you provide some sorts of example if possible?
z

Zach Klippenstein (he/him) [MOD]

12/18/2023, 5:18 PM
Copy code
var textFieldValue by remember { mutableStateOf(TextFieldValue(number, selection = number.length) }
TextField(textFieldValue, onValueChange = { textFieldValue = it })