Author Topic: Character limit of UIInput has no effect on device keyboard  (Read 4727 times)

Grhyll

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Hello,

I'm using the Max chars property on some of my UIInput fields, and it works great on editor, however on iOS (and maybe on Android, I haven't tested yet) it only cut the label when the user ends up writing.
It would be great that the user can't write more characters than the limit in the system keyboard.
I tried to change UIInput.cs, changing the order of the following two lines in the Update function :

  1.                                 if (mText != text) mKeyboard.text = mText;
  2.                                 UpdateLabel();

It almost worked, but the user can see the last character he types before it is removed because of the chars limit.
Would you have any idea of how to do this properly, without the user being able to see the additionnal character before it is removed?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Character limit of UIInput has no effect on device keyboard
« Reply #1 on: May 05, 2013, 12:13:18 PM »
Add this line in ios/android's Update function (line 318):
  1. if (maxChars > 0 && mText.Length > maxChars) mText = mText.Substring(0, maxChars);
It should be right above:
  1. if (mText != text) mKeyboard.text = mText;
  2. UpdateLabel();

Grhyll

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: Character limit of UIInput has no effect on device keyboard
« Reply #2 on: May 06, 2013, 02:51:55 AM »
Thank you for the answer. However, it keeps the same problem I was describing in my original post (the user can briefly see the new letter written before it is removed). Maybe it is because I don't work yet with the latest version of NGUI (I did not update it in the past few months, and we are very close to the deadline so we are kind of afraid to do anything that could bring unwanted changes in our UI).
This new code line had to be put at line 284 in the version I use (instead of 318). Do you think that with the latest version it will work perfectly (the new letter can't be seen at all if user tries to exceed limit), or the problem will be the same?
Thank you.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Character limit of UIInput has no effect on device keyboard
« Reply #3 on: May 06, 2013, 04:10:59 PM »
It will probably behave the same.

Grhyll

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: Character limit of UIInput has no effect on device keyboard
« Reply #4 on: May 07, 2013, 06:55:09 AM »
Thank you.