Author Topic: UIInput & Validation problems on Android  (Read 13242 times)

Tripwire

  • Full Member
  • ***
  • Thank You
  • -Given: 9
  • -Receive: 0
  • Posts: 163
    • View Profile
UIInput & Validation problems on Android
« on: July 10, 2014, 09:11:40 AM »
Hi,

I'm having some weird problems with the UIInput and Validation of the input on Android.
I've added these lines to the UIInput script:
In the Validation enum
  1. Decimal
  2.  

In the Validate function
  1. else if (validation == Validation.Decimal)
  2. {
  3.         //Decimal numbers
  4.         if (ch >= '0' && ch <= '9') return ch;
  5.         if (ch == '-' && pos == 0 && !text.Contains("-")) return ch;
  6.         if (ch == ',' && !text.Contains(",")) return ch;
  7. }
  8.  

This works perfectly on my mac. But when running on my Samsung Galaxy Tab I can't add the comma in my input field. Also when the input validation to float, I can't seem to add the '.' character.

The other problem i'm having is when setting the Hide Input to true, the input field is hidden but the backspace isn't working anymore.

My UIInput settings:


Any idea how to fix these problems?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIInput & Validation problems on Android
« Reply #1 on: July 10, 2014, 09:20:11 PM »
What's "Decimal"? There is already "Float". How does it differ?

The function you added validates a comma, yet you are trying to input a period. Not sure how you expect it to work...

I just dragged in an input field into the scene, chose Float validation, NumberPad keyboard, and Hide Input. I then built for Android and was able to type "123.45", as expected.

Tripwire

  • Full Member
  • ***
  • Thank You
  • -Given: 9
  • -Receive: 0
  • Posts: 163
    • View Profile
Re: UIInput & Validation problems on Android
« Reply #2 on: July 11, 2014, 02:52:40 AM »
What's "Decimal"? There is already "Float". How does it differ?

The function you added validates a comma, yet you are trying to input a period. Not sure how you expect it to work...

I just dragged in an input field into the scene, chose Float validation, NumberPad keyboard, and Hide Input. I then built for Android and was able to type "123.45", as expected.

Hi ArenMook,

Thanks for your reply! The Decimal variable is used for currency. I'm Dutch, and in Dutch we say for instance €10,99 whereas in the USA they say $10.99. I need that comma seperator for currency. So I decided to make a extra validation enum for Decimal.

What I meant, was that when validation setting to float I can't input a dot in the input fields on my Android Device. And that's the same when using the Decimal validation and trying to input a comma.

EDIT:
When setting the keyboard type to NumbersAndPunctuation the dot works for Float but I still can't input a comma. I've changed the Float validation since i'm not validating floats anywhere in my app to this:
  1. // Floating-point number
  2. if (ch >= '0' && ch <= '9') return ch;
  3. if (ch == '-' && pos == 0 && !text.Contains("-")) return ch;
  4. if (ch == '.' && !text.Contains(".") && !text.Contains(",")) return ch;
  5. if (ch == ',' && !text.Contains(",") && !text.Contains(".")) return ch;
  6.  

In the Unity3D Editor on my Mac I can input the dot OR the comma not both what is exactly what I wanted. But when I run it on my Android device I can only input a dot and not a comma :(
« Last Edit: July 11, 2014, 03:56:34 AM by Tripwire »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIInput & Validation problems on Android
« Reply #3 on: July 11, 2014, 08:05:18 PM »
NGUi simply goes by what Unity and the OS feeds it. Does it even receive the comma? Did you check that? Also try printing out what NGUI is validating there.

Tripwire

  • Full Member
  • ***
  • Thank You
  • -Given: 9
  • -Receive: 0
  • Posts: 163
    • View Profile
Re: UIInput & Validation problems on Android
« Reply #4 on: July 25, 2014, 07:14:56 AM »
NGUi simply goes by what Unity and the OS feeds it. Does it even receive the comma? Did you check that? Also try printing out what NGUI is validating there.

Hi ArenMook,

I finally had time to debug this problem some more. I've checked the input with an GUI.TextField and there it is printing commas.
I've checked the settings with Decimal validation and keyboard type:
- Default -> Comma's work
- ASCIICapable -> Comma's work
- NumbersAndPunctuation -> No comma's in validation and in UIInput field and in Eclipse Logcat
- URL -> Comma's work
- NumberPad -> No comma's in validation and in UIInput and in Eclipse Logcat
- PhonePad -> Comma's work
- NamePhonePad -> Comma's work
- EmailAddress ->Comma's work

I'm using the latest version of NGUI downloaded from the Asset store and i'm using the latest version of Unity3D (4.5.2).

Here's the current code for Decimal validation:
  1. public enum Validation
  2. {
  3.         None,
  4.         Integer,
  5.         Float,
  6.         Alphanumeric,
  7.         Username,
  8.         Decimal,
  9.         Name,
  10. }
  11.  
  12.  
  13. else if (validation == Validation.Decimal)
  14. {
  15.         Debug.Log ("text: " + text + " pos: " + pos + " char: " + ch);
  16.         // Decimal number
  17.         if (ch >= '0' && ch <= '9') return ch;
  18.         if (ch == ',' && !text.Contains(",")) return ch;
  19. }
  20.  

Any idea?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIInput & Validation problems on Android
« Reply #5 on: July 26, 2014, 12:29:01 AM »
GUI.TextField is a completely different beast. NGUI's input field data comes either from the TouchScreenKeyboard, or from Input.inputString, depending on the platform.

If commas don't show up in the log, then that's just what Unity passes to NGUI.

Tripwire

  • Full Member
  • ***
  • Thank You
  • -Given: 9
  • -Receive: 0
  • Posts: 163
    • View Profile
Re: UIInput & Validation problems on Android
« Reply #6 on: July 28, 2014, 03:54:14 AM »
GUI.TextField is a completely different beast. NGUI's input field data comes either from the TouchScreenKeyboard, or from Input.inputString, depending on the platform.

If commas don't show up in the log, then that's just what Unity passes to NGUI.

Right so i've checked out what you said:

Created an empty project with nothing in it, just a main camera and the script below for testing:
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Test : MonoBehaviour {
  5.  
  6.         private string  inputText01,
  7.                                         inputText02;
  8.  
  9.         private TouchScreenKeyboard keyboard01,
  10.                                                                 keyboard02;
  11.  
  12.         void OnGUI()
  13.         {
  14.                 if(GUI.Button(new Rect(10, 10, 100, 100), "Number!"))
  15.                 {
  16.                         keyboard01 = TouchScreenKeyboard.Open(inputText01, TouchScreenKeyboardType.NumberPad, false, false, false, false);
  17.  
  18.                         if(keyboard01.active)
  19.                                 Debug.Log(inputText01);
  20.                 }
  21.  
  22.  
  23.                 if(GUI.Button(new Rect(10, 300, 100, 100), "NP"))
  24.                 {
  25.                         keyboard02 = TouchScreenKeyboard.Open(inputText02, TouchScreenKeyboardType.NumbersAndPunctuation, false, false, false, false);
  26.  
  27.                         if(keyboard02.active)
  28.                                 Debug.Log (inputText02);
  29.                 }
  30.         }
  31. }
  32.  

It seems to be a Unity3D bug because:
- Unity 4.2 commas work when using the NumbersAndPuncturation keyboard
- Unity 4.3 commas work when using the NumbersAndPuncturation keyboard
- Unity 4.5 commas don't work anymore :(

I'll report a bug. Thing is when I revert my project back to Unity 4.3 the comma's still aren't working...

EDIT:
Reverted back to an older version which hasn't been opened in Unity 4.5 and now commas work with Decimal validation :) I've reported this bug to Unity3D hop they'll fix in in their next release.

EDIT 2:
Got an email from Unity3D back that they've acknowledged the bug and that they are going to fix it.
« Last Edit: July 28, 2014, 09:33:19 AM by Tripwire »