Author Topic: [SOLVED] BUG: UIInput not hiding password if text set from code  (Read 4898 times)

helmesjo

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 116
    • View Profile
Hola!

Basically, setting the UIInput.text-property from code will not hide the characters for passwords. After some quick digging I found that the UILabel.password-property was never set in Init() of UIInput, only in OnSelected()... I think you just took for granted that the password would always be typed in. ;)

Here is my fix (in UIInput):

  1. protected void Init ()
  2.         {
  3.                 if (mDoInit)
  4.                 {
  5.                         mDoInit = false;
  6.                         if (label == null) label = GetComponentInChildren<UILabel>();
  7.  
  8.                         if (label != null)
  9.                         {
  10.                                 if (useLabelTextAtStart) mText = label.text;
  11.                                 mDefaultText = label.text;
  12.                                 mDefaultColor = label.color;
  13.                                 label.supportEncoding = false;
  14.                                 mPivot = label.pivot;
  15.                                 mPosition = label.cachedTransform.localPosition.x;
  16.                                
  17.                                 //Zup yo!<---------------------------------------------------------------
  18.                                 if (isPassword)
  19.                                         label.password = true;
  20.                                 //-----------------------------------------------------------------------
  21.                         }
  22.                         else enabled = false;
  23.                 }
  24.         }
  25.  

Cheers!
« Last Edit: March 26, 2013, 03:42:30 AM by helmesjo »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: BUG(?): UIInput not hiding password if text set from code
« Reply #1 on: March 25, 2013, 08:44:00 PM »
You're right. I will add the fix, thanks.

patm

  • Guest
Re: [SOLVED] BUG: UIInput not hiding password if text set from code
« Reply #2 on: April 10, 2013, 09:55:23 PM »
Doesn't appear to be fixed. Just ran into this so I checked and there was an NGUI update available. It has "label.password = isPassword;" in Init() but setting the .text from code results in clear text in the label. If I type it shows stars. If I add via code after typing it shows stars. If I select the label (which clears it) and hit enter without typing then subsequent sets from code are clear text again.