0

Is there 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.

Thanks!

Kane
  • 375
  • 1
  • 6
  • 18

2 Answers2

2

You can similarly limit your input field to a single line by setting the Max Lines property to 1 on the UILabel.

http://www.tasharen.com/forum/index.php?topic=6752.0

Diplomat
  • 181
  • 1
  • 4
0

Had to check the UIInput.cs file to know how to ignore newlines, and I found this:

case KeyCode.KeypadEnter:
            {
                ev.Use();

                bool newLine = (onReturnKey == OnReturnKey.NewLine) ||
                    (onReturnKey == OnReturnKey.Default &&
                    label.multiLine && !ctrl &&
                    label.overflowMethod != UILabel.Overflow.ClampContent &&
                    validation == Validation.None);

                if (newLine)
                {
                    //Insert("\n");
                }
                else
                {
                    UICamera.currentScheme = UICamera.ControlScheme.Controller;
                    UICamera.currentKey = ev.keyCode;
                    Submit();
                    UICamera.currentKey = KeyCode.None;
                }
                return true;
            }

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();

Kane
  • 375
  • 1
  • 6
  • 18