InputField caret placement after .Select()

I need to both select my InputField AND place the caret at the end of that field when a user performs an action. While I can select the InputField just fine, I can’t make the caret display where I want it to. Calling InputField.Select() or InputField.ActivateInputField() selects all text, but then none of the selection or caret position properties seem to do anything.

Here is my code:

this.search.inputFieldSearch.ActivateInputField();
this.search.inputFieldSearch.selectionAnchorPosition = this.search.inputFieldSearch.text.Length-1;
this.search.inputFieldSearch.selectionFocusPosition = this.search.inputFieldSearch.text.Length-1;
this.search.inputFieldSearch.caretPosition = this.search.inputFieldSearch.text.Length-1;

I would expect this to leave the blinking caret at the end of the text in the InputField, but instead it highlights the whole field. Any insight from anyone on this?

1 Like

I’m experiencing the exact same problem (in 5.3), and it’s really rather annoying. The caret can’t event be set to the end of the input field by using inputField.ProcessEvent(KeyboardEvent(“end”)). The text is added to the end of the input field after processing that keyboard event, but the selection remains.

Anyone have any ideas on the matter, or is a bug report in order?

Edit: This post ended up being the cleanest fix to the problem - simply inherit from InputField and add the described bits of code.