Author Topic: Avoid line-break in UIInput  (Read 2753 times)

Kane

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Avoid line-break in UIInput
« on: October 21, 2014, 07:39:50 PM »
Hello!

I am using the version 3.5.9, and I am wondering if there is any way to avoid users to input line-breaks in UIInputs.

Do not want the user to be able to write line-breaks in username inputs, for example.

I searched for multiline attribute but it seems it only exists in UILabel objects.

Tried "validation:Username" but this option does not allow to write characters like "-", which is a valid username character of my application.

Any idea to avoid line-break?

Thanks! : )

Kane

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Avoid line-break in UIInput
« Reply #1 on: October 22, 2014, 04:02:46 AM »
Had to check the UIInput.cs file to know how to ignore newlines, and I found this:

  1. case KeyCode.KeypadEnter:
  2.                         {
  3.                                 ev.Use();
  4.  
  5.                                 bool newLine = (onReturnKey == OnReturnKey.NewLine) ||
  6.                                         (onReturnKey == OnReturnKey.Default &&
  7.                                         label.multiLine && !ctrl &&
  8.                                         label.overflowMethod != UILabel.Overflow.ClampContent &&
  9.                                         validation == Validation.None);
  10.  
  11.                                 if (newLine)
  12.                                 {
  13.                     //Insert("\n");
  14.                                 }
  15.                                 else
  16.                                 {
  17.                                         UICamera.currentScheme = UICamera.ControlScheme.Controller;
  18.                                         UICamera.currentKey = ev.keyCode;
  19.                                         Submit();
  20.                                         UICamera.currentKey = KeyCode.None;
  21.                                 }
  22.                                 return true;
  23.                         }

So in order to avoid newlines, you need to do:

UILabelObject.multiLine = false;

UIInputObject.onReturnKey = UIInput.OnReturnKey.Default;


Doing that, bool newLine becomes false and performs Submit();


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Avoid line-break in UIInput
« Reply #2 on: October 22, 2014, 05:48:25 AM »
Select the UILabel used by the input field and change its max lines to 1.