0

Following this highly upvoted solution, I tried setting the cursor position of a TextField in iOS but it throws an error saying textRange is not a function.

<TextField :text="someVariable" @focus="setCursor" />

script part:

setCursor(args) {
    const iosTextField = args.object.ios;
    const newPosition = iosTextField.endOfDocument;

    // throws an error, textRange is not a function
    iosTextField.selectedTextRange = iosTextField.textRange(newPosition, newPosition); 
    
}

Also, console logging newPosition, iosTextField.selectedTextRange.start & iosTextField.selectedTextRange.end gives something like this:

<_UITextLayoutPosition: 0x60000086bd20; location = 0, affinity = forward>

The value of location for newPosition is always equal to the length of the string.

Am I missing out on something? Why isn't textRange method available? Is there any other way of setting the cursor position of TextField in Nativescript iOS?

saibbyweb
  • 2,269
  • 2
  • 20
  • 39

0 Answers0