Hi All,
I’ve got a weird bug where any TMP Input Field that has a custom validator attached to it causes this weird behaviour when built to either Android or iOS.
Nature of the behaviour:
- Duplicates the existing text
- Won’t let me delete it
- Only happens with Custom Validators AND iOS/Android Builds. Testing in editor or just choosing one of the pre-set validators does not produce this issue.
Notes about the project and what I’ve tried:
- Making an AR project with AR Foundation.
- The input field pictured in the video is as default as you can get. Not apart of any prefabs and no custom scripts affecting it.
- Tried both my own as well as unity’s example validators. Behaviour is produced with all custom validators.
- Testing in the editor works exactly as you would expect.
Any guidance on this issue would be super helpful!
valideveryeft
Bump. Facing the issue with TextMeshPro 3.0.6 and unity 21.3.26f1.
Edit: Fixed it by upgrading to preview TextMeshPro version 3.2.0-pre.4
Here’s a fix, assuming that your custom input validator modifies its text
ref argument directly.
Change the return value so it always returns ‘\0’:
public override char Validate(ref string text, ref int pos, char ch)
{
text = SomeFunctionThatFormatsOrValidatesText(text);
return '\0';
}
This solves the issue because Validate is invoked after ch
has already been appended to text
. By returning ‘\0’, we prevent TextMesh Pro from appending extraneous characters.
My validator formats a phone number “(###) ### - ####” and needs to insert the parenthesis, hyphen and spaces. These characters cannot be entered by the user and therefore they can only be added by assigning to the text argument directly.
There is some wasted cycles with this approach. TMP_InputField calls the validator for every character in the input field’s text. This means text
is repeatedly formatted/reassigned even though one pass is likely sufficient. However, this does solve the duplicate characters issue and inability to backspace the input entirely on Android and iOS.