Okay. I’ve been working with Unity UI’s InputField class for some time now, and I’m frustrated enough by its limitations that I felt the need to start a thread. I have two major complaints about it, along with suggestions for how to fix them!
-
PROBLEM 1: The ActivateInputField() method auto-selects all text in the activated InputField. This is hugely inappropriate for large text fields–it leads to frustrating situations where users accidentally erase loads of text when they start typing, having expected the cursor to appear at the end of the field. People have been complaining about this for years , and nothing has been done.
-
SOLUTION 1: As of right now, the only solution I’ve seen involves scripting a custom extension to Input Field, a tricky and deeply-user-unfriendly means of achieving a basic feature that really ought to be available out of the box. To fix the problem, the Input Field (Script) component should receive a radio button in the editor that, when toggled on, sets a boolean in the script that calls MoveToEnd() in LateUpdate upon activation. This will give developers the choice of whether to use the default “select all” behavior or not.
-
PROBLEM 2: Input fields do not support custom character validation. As of right now, an input field set to custom content has only six preset options for character validation: None, Integer, Decimal, Alphanumeric, Name, and Email Address. This would merely be disappointing on its own–but in combination with Problem 1, it leads to nightmare situations like this:
-
developer has a collection of multi-line InputFields that he wants the user to be able to navigate through using the Tab key. (He does not want Tab to navigate through other UI elements–just the input fields.)
-
developer puts all the input fields into a list, then implements a listener in Update()-- *Input.GetKeyDown( KeyCode.Tab )–*and uses it to call ActivateInputField() on the next InputField in the list. Because of Problem 1, every time this happens, the input field that gets activated will auto-select all of its text.
-
using this tab navigation feature to quickly jump between several multi-line InputFields will then result in the contents of each field being erased and replaced with a tab. Because of Problem 2, there is no way for the developer to specifically prohibit typing in tab characters in this way without also excluding other white space characters or introducing unwanted behaviors (like auto-capitalization).
-
SOLUTION 2: To fix the problem, the Input Field (Script) component should receive a Custom character validation type. When selected, Custom character validation should add a field to the editor component where excluded characters can be typed in–perhaps utilizing a variant on RegEx syntax. (If left blank, the InputField would simply behave as though it had a character validation type of None.)
I’d be very interested to hear from a Unity developer about the feasibility of implementing one or both of these features.