Search Unity

Can't select TextField text

Discussion in 'UI Toolkit' started by Deleted User, Jan 26, 2019.

  1. Deleted User

    Deleted User

    Guest

    I've made a custom inspector window with a TextField, but I can't select the text. Clicking the TextField hides the existing text shows an empty box.

    How do I disable this behaviour?
     
  2. Deleted User

    Deleted User

    Guest

    It seems the issue was an incorrect comment:

    Code (CSharp):
    1. /// <summary>
    2. ///   <para>Creates a new textfield.</para>
    3. /// </summary>
    4. /// <param name="maxLength">The maximum number of characters this textfield can hold. If 0, there is no limit.</param>
    5. /// <param name="multiline">Set this to true to allow multiple lines in the textfield and false if otherwise.</param>
    6. /// <param name="isPasswordField">Set this to true to mask the characters and false if otherwise.</param>
    7. /// <param name="maskChar">The character used for masking in a password field.</param>
    8. public TextField (int maxLength, bool multiline, bool isPasswordField, char maskChar)


    Setting 'maxLength' to 0 results in the behaviour I described.
    Setting it to int.MaxValue instead seems to fix the problem.
     
  3. jeanfrancois_unity

    jeanfrancois_unity

    Unity Technologies

    Joined:
    Oct 24, 2018
    Posts:
    4
    Try setting the 'maxLength' to a negative number like -1. This value is in sync with the actual code of the TextField.

    It seems the documentation is wrong and 0 is not "no limit" but negative numbers are...
    FYI, we are in the process of "fixing" the documentation.
     
  4. Deleted User

    Deleted User

    Guest

    Awesome, thanks for the heads up. I eventually got everything figured out.

    I needed an editor window for working on 200+ scene objects. It was unusably slow with IMGUI, but perfectly smooth with UIElements, so I'm pretty happy with UIElements at the moment.

    Thanks!
     
  5. giant_lindsay

    giant_lindsay

    Joined:
    Nov 30, 2015
    Posts:
    3
    I just spent ages trying to fix this problem, and found that yes having 0 would cause my textfield to be empty when focussed. The documentation is wrong and needs to be fixed!