Input Field Upper Case?

Hi all
I am not sure this question is asked before or not. I have searched and couldn’t find. I want user to input in upper case in input field. I have tried:
public void OnValueChange()
{
inputField.text=inputField.text.toUpper();
}

This seems to work on desktop. HOwever, when I test it on android, application crashes. Does anybody have any idea?

This is just pure hypothetical since I am on my phone and can’t look up the code. Does setting the input fields text call OnValueChanged on Android? That would cause a Stack overflow and crash the ap.

I don’t have any idea, but maybe you should store the value to some temporary variable and compare the value first so it won’t loop infintely, something like

var upperText = inputField.text.toUpper();
if (upperText != inputField.text) inputField.text = upperText;
1 Like

No way, still same. Anyone?

Yes it calls the function

@Tim-C please help me!!!

Tim’s not the one you’re looking for :).

I’ll have to take a look. I’m not sure what would be causing a crash.

Hello phil-Unity
This is the first time I have problem with UI, so I dont know whom to be contact with:) Thanks for your help.

So i found the issue and have fixed it locally. Needless to say i’m surprised no one caught this earlier…

ATM i dont think there is any work around unless you are willing to pull source then i can point you to the line to fix.

public void NameInputFieldValueChange()
{
if(nameInputField.text==“”)
{
okButton.interactable=false;
okButtonText.color= new Color(0.93f,0.65f,0.37f,1);
okTextOutline.effectColor= new Color(0.93f,0.65f,0.37f,0.5f);
}
else
{
okButton.interactable=true;
okButtonText.color= new Color(1,0.92f,0.37f);
okTextOutline.effectColor= new Color(0.517f,0.188f,0,0.5f);
nameInputField.text=nameInputField.text.ToUpper();
}
}

Here is the only code related to InputField. I assigned this method to OnValueChange event trigger of InputField. What should I do?

What your doing is fine, there was just a bug in the inputfield itself which i have fixed. You’d have to pull the whole UI source from https://bitbucket.org/Unity-Technologies/ui/overview to be able to get the fix right now or wait until at least the next patch release (p4). My guess though is that it will be p5 not p4.

I will wait patch release. I dont know how to change source code.Thanks for this bug fix. Good job:)

Once one downloads, do you just override the existing Unity files within the install folder?

The details explain how do it… (i’ve never done it) but i think its a matter of downloading, compiling (in your fav ide), copy the output to the specified folder, run unity.

Hi phil-Unity

you said problem will be solved in p5. I have installed unity4.6.2 but problem is still there:( But this time a bit different. Previously, aplication was crashing when I write from keyboard, now when I write something application restart again. Still, I cannot write in upper case in inputfield. What should I do?

I have discovered that when I write in upper case letters(from keyboard), it does not restart again. However when I write in lower case from keyboard, it restarts application. Interesting…

problem is still there. Case 669286

Try with 4.6.2p1 when it comes out. I just pushed a bunch of changes (we were way behind on getting the UI fixes into a release).

Is it possible that this showed back up in 5.6? I wasn’t having the problem in 5.2.3, but am updating my app and was crashing with the looping problem when trying to force all caps.

Hey there i’m using the onValidateInput callback :slight_smile:

    private void Awake() {
        yourInputField.onValidateInput += delegate (string input, int charIndex, char addedChar) { return SetToUpper(addedChar); };
    }

    public char SetToUpper(char c) {
        string str = c.ToString().ToUpper();
        char[] chars = str.ToCharArray();
        return chars[0];
    }

Maybe not the best way but works perfectly

2 Likes