Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Submit TMP_InputField with a single submit keypress?

Discussion in 'UGUI & TextMesh Pro' started by bunp, Feb 17, 2024.

  1. bunp

    bunp

    Joined:
    Feb 21, 2019
    Posts:
    70
    How do I make it so when I hit submit on a unity TMP_InputField that it submits the field, as in calls whatever submit method?

    Currently I am using the ISubmitHandler interface but it does not submit when you hit submit the first time, because the first 'submit' press instead calls OnEndEdit, and then the SECOND press of submit calls OnSubmit.

    OnEndEdit which I cannot use because OnEndEdit is ALSO called when you deselect the TMP_Inputfield, which I do not want to always submit the field every time it gets deselected
     
  2. bunp

    bunp

    Joined:
    Feb 21, 2019
    Posts:
    70
    The problem I need to find a work around for is: TMP_InputField, you hit 'Submit' (in this context, Enter key on a keyboard) The first press calls OnEndEdit of the field, but doesn't call the EventSystem ISubmitHandler OnSubmit method https://docs.unity3d.com/2019.1/Documentation/ScriptReference/EventSystems.ISubmitHandler.html

    Only on a second subsequent press does OnSubmit get called. I want to call my own code and advance the game state on submit, simultaneously with ending edit of the input field. The problem is that I cannot just use OnEndEdit directly because OnEndEdit is also called when you Deselect the TMP_InputField, and there is no possible way I can find to differentiate if the OnEndEdit was called by deselection of the field or from pressing submit callback from the EventSystem

    I have not been able to find any solution for this that allows me to make the TMP_InputField work like any other normal system text input field, eg; hitting enter once sends it, deselecting does not send it. and its not really reasonable to ask the end user to just hit enter twice in my mind, just because I have not been able to figure out how to make it work on a single OnSubmit.