Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[SOLVED] UI Toolkit TextField clear TextInput

Discussion in 'UI Toolkit' started by gueni, Feb 14, 2021.

  1. gueni

    gueni

    Joined:
    May 25, 2017
    Posts:
    4
    Hi

    after typing in TextInput of a TextField I want to clear the TextInput string (like in a chat after sending the string the TextInput should be empty but i dont know how. It says there is no setter for the TextInput to set it to an empty string with "".

    I am accessing the TextField with .Q<TextField>("TextField"); and i can read the string in c# which i type but dont know how to clear.

    I ca'nt even read the TextInput directly with .Q<TextField>("unity-text-input"); (someone mentioned that in a different thread hier in the forums) but that wouldn't help anyway if there's no setter.

    thanks in advance
     
  2. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    754
    I figured it out:

    Code (CSharp):
    1. nameTagTextField.SetValueWithoutNotify("test");
     
    Mj-Kkaya and gueni like this.
  3. griendeau_unity

    griendeau_unity

    Unity Technologies

    Joined:
    Aug 25, 2020
    Posts:
    230
    Thanks MousePods, SetValueWithoutNotify() is a way to do it, when you need to change the text only.

    You can also use
    textField.value = ".."
    if you need to notify anyone registered to that text field's value changed callback.
     
    Mj-Kkaya, gueni and MousePods like this.
  4. gueni

    gueni

    Joined:
    May 25, 2017
    Posts:
    4
    thx much
     
    griendeau_unity and MousePods like this.