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

Retain InputField Focus after submit?

Discussion in 'UGUI & TextMesh Pro' started by Thiago-Crawford, Sep 18, 2014.

  1. Thiago-Crawford

    Thiago-Crawford

    Joined:
    Jan 7, 2013
    Posts:
    92
    Hi,

    I just want to know how to do a simple task, after the user submits the text in an Inputfield, I want the input field to retain its focus.

    So the user can just type a new line into the same inputfield (like one would expect in a chat box), without having to click on it again.

    So how can I do this through script? (C# please)

    Thanks!
     
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,181
    You can call:
    ActivateInputField ();
     
  3. Thiago-Crawford

    Thiago-Crawford

    Joined:
    Jan 7, 2013
    Posts:
    92
    I'm still not sure which object can make that call?

    myInputField.ActivateInputField();
    or somethingElse.ActivateInputField(); ?

    Thanks :)
     
  4. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    it would be myInputField.ActivateInputField as thats the only object with that function call.
     
  5. Thiago-Crawford

    Thiago-Crawford

    Joined:
    Jan 7, 2013
    Posts:
    92
    I thought that would be the case, but I don't seem to have the option available to me.

    "...: error CS0122: `UnityEngine.UI.InputField.ActivateInputField()' is inaccessible due to its protection level"

    Version 4.6.0b18

    Is there something I might be doing wrong or is it just my beta version is older/doesn't have it yet available?
     
  6. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    I assume it was changed in upcoming b19 they use as now it's indeed private.
     
  7. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Hmm the change was done 3 weeks ago. so i would have thought they'd be in b18. but if not then for sure b19.
     
  8. Thiago-Crawford

    Thiago-Crawford

    Joined:
    Jan 7, 2013
    Posts:
    92
    Hey, just got beta 19, the ActivateInputField works now, but I'm still having trouble getting the exact behavior I would like.

    Basically, I need to know where to add this call in my code.

    My current code:

    void Start () {
    userAnswerInputField.onSubmit.AddListener (SubmitUserText);
    }

    public void SubmitUserText (string userText) {
    userAnswerInputField.ActivateInputField ();
    }

    But this doesn't get the text ready to type again.

    --------

    If i put it like this though it works as I want...

    void Update () {
    userAnswerInputField.ActivateInputField ();
    }

    However is there a call that takes place I could use instead of update? like OnInputFieldBecameInactive() type thing? Or do I have to keep it in the Update loop?
     
    Last edited: Sep 23, 2014
  9. bdominguezvw

    bdominguezvw

    Joined:
    Dec 4, 2013
    Posts:
    96
    My problem is that I want that when I press "Tab" key change focus from one control to another.

    If I use "ActivateInputField()" it acts weird.:

    - It puts the caret symbol in the second input but it doesn't remove the caret of the first input
    - The focus remains in the first input, I can't write in the second input if I don't click on it.
     
  10. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    I'll spend some time this week looking into this.
     
  11. bdominguezvw

    bdominguezvw

    Joined:
    Dec 4, 2013
    Posts:
    96
    Any news on this? It's fixed on beta 20?
     
  12. unity_VvCODKknmBJQGw

    unity_VvCODKknmBJQGw

    Joined:
    Aug 13, 2020
    Posts:
    7
    I love you.
     
  13. BerkayKomurcugil

    BerkayKomurcugil

    Joined:
    Mar 16, 2019
    Posts:
    1
    I LOVE YOU MAN