Search Unity

Simple concept - InputField doing something when submitted

Discussion in 'UGUI & TextMesh Pro' started by cowtrix, Aug 25, 2014.

  1. cowtrix

    cowtrix

    Joined:
    Oct 23, 2012
    Posts:
    322
    Hi guys. Quick question about using InputFields - how do you subscribe to an event when the field is submitted (enter is pressed) in another script to do something? The specific use case here is an Input Field that should append a text box with the inputted text when submitted, and clear itself. It also has to go through a script to append, as some parsing is done.

    Cheers!
     
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Hi, there is an onSubmit event on the InputField, it's not in the inspector atm (bug) but you can access it via code until we fix this.
     
  3. cowtrix

    cowtrix

    Joined:
    Oct 23, 2012
    Posts:
    322
    Hey Tim, yeah that was my first port of call but I can't figure out what kind of code I need. Is it something like:
    Inputfield.onSubmit += DoSomething();
    and then:
    void DoSomething()
    {
    }
    Because that throws errors. What does the subscription look like?
     
  4. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Inputfield.onSubmit.AddListener(DoSomething);