Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Input Field Upper Case?

Discussion in 'UGUI & TextMesh Pro' started by Gokcan, Jan 12, 2015.

  1. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    289
    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?
     
  2. BMayne

    BMayne

    Joined:
    Aug 4, 2014
    Posts:
    186
    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.
     
  3. thienhaflash

    thienhaflash

    Joined:
    Jun 16, 2012
    Posts:
    513
    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
    Code (CSharp):
    1. var upperText = inputField.text.toUpper();
    2. if (upperText != inputField.text) inputField.text = upperText;
     
    megabrobro likes this.
  4. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    289
    No way, still same. Anyone?
     
  5. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    289
    Yes it calls the function
     
  6. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    289
  7. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    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.
     
  8. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    289
    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.
     
  9. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    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.
     
  10. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    289
    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?
     
  11. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    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.
     
  12. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    289
    I will wait patch release. I dont know how to change source code.Thanks for this bug fix. Good job:)
     
  13. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Once one downloads, do you just override the existing Unity files within the install folder?
     
  14. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    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.
     
  15. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    289
    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?
     
  16. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    289
    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...
     
  17. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    289
    problem is still there. Case 669286
     
  18. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    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).
     
  19. BigToe

    BigToe

    Joined:
    Nov 1, 2010
    Posts:
    204
    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.
     
  20. JannickL

    JannickL

    Joined:
    May 18, 2016
    Posts:
    78
    Hey there i'm using the onValidateInput callback :)

    Code (CSharp):
    1.     private void Awake() {
    2.         yourInputField.onValidateInput += delegate (string input, int charIndex, char addedChar) { return SetToUpper(addedChar); };
    3.     }
    4.  
    5.     public char SetToUpper(char c) {
    6.         string str = c.ToString().ToUpper();
    7.         char[] chars = str.ToCharArray();
    8.         return chars[0];
    9.     }
    Maybe not the best way but works perfectly
     
    Last edited: Sep 1, 2018
    JDeyby and dizzymediainc like this.
  21. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    The idea is sound. You could also do:
    Code (csharp):
    1. public char SetToUpper(char c) {
    2.    return char.ToUpper(c);
    3.   }
     
  22. dizzymediainc

    dizzymediainc

    Joined:
    Apr 6, 2014
    Posts:
    389

    This worked like a charm, thanks!