Search Unity

TextMesh Pro Textmesh Pro Input Fied OnSubmit Event

Discussion in 'UGUI & TextMesh Pro' started by Airship, Aug 20, 2018.

  1. Airship

    Airship

    Joined:
    Sep 10, 2011
    Posts:
    260
    I am noticing that the OnSubmit Event fires on Android and in the Unity Editor, but not on iOS. I would expect it to fire on iOS when the user pressed "Done" on the keyboard, but it does not.

    Has anyone else noticed this? OnEndEdit works on iOS, but I need the OnSubmit granularity.
     
  2. Aleksander87

    Aleksander87

    Joined:
    Jul 7, 2017
    Posts:
    20
    Same problem here
     
  3. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I believe this is a platform specific limitation. I'll double check.
     
  4. Aleksander87

    Aleksander87

    Joined:
    Jul 7, 2017
    Posts:
    20
    If someone still need this, there is a workaround (used for the old input fields) that can be applied in this case too:
    - extended TMP_InputField with a custom script;
    - add an Update() where you check the state of the keyboard

    if(this.m_Keyboard.status == TouchScreenKeyboard.Status.Done)
    {
    //This is a submit​
    }
     
    ziemlich3D likes this.
  5. ziemlich3D

    ziemlich3D

    Joined:
    Aug 21, 2017
    Posts:
    24
    Thank you very much for your answer! This was exactly I was searching for a long time :)
     
    ABI16 likes this.
  6. ABI16

    ABI16

    Joined:
    Mar 19, 2019
    Posts:
    16
    Im sorry to ask this, but can you please post the code on how you extend the TMP_InputField? Thanks in advance.
     
  7. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    That's another way of saying that you define your own class that inherits from TMP_InputField:

    public class MyClass : TMP_InputField


    Then, when building your scene, you use your class instead of the original TMP_InputField component.
     
    ABI16 likes this.
  8. ABI16

    ABI16

    Joined:
    Mar 19, 2019
    Posts:
    16
    Thanks a lot @Antistone
     
  9. ypatelzynga

    ypatelzynga

    Joined:
    Aug 30, 2018
    Posts:
    9
    i am using TMP input filed for chat system... we want to post chat message as soon as player press okay button from android key board and Done button from IOS key board... I am registering to OnSubmit event for TMP input filed and game client post message in chat window when it receives that event. This works fine with Andriod OS but it does not work well on IOS. it seems like pressing Done button on IOS does not post message all it does is hide keyboard. I tried using OnEndEdit() but it submit text in chat window even though player click out side of key board. How can i register to IoS "Done" button using TMP
     
  10. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    Have you tried Aleksander87's suggested workaround, posted above?
     
  11. jpgordon00

    jpgordon00

    Joined:
    Jan 9, 2021
    Posts:
    25
    Here is code that I use:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.SceneManagement;
    6. using TMPro;
    7.  
    8. namespace TMPro
    9. {
    10.  
    11.     public class InputField : TMP_InputField
    12.     {
    13.  
    14.         /// <summary>
    15.         /// Update the text based on input.
    16.         /// </summary>
    17.         // TODO: Make LateUpdate a coroutine instead. Allows us to control the update to only be when the field is active.
    18.         protected override void LateUpdate()
    19.         {
    20.             if (m_SoftKeyboard == null)
    21.             {
    22.                 base.LateUpdate();
    23.                 return;
    24.             }
    25.             if (m_SoftKeyboard.status != TouchScreenKeyboard.Status.Visible) {
    26.                 if (this.m_SoftKeyboard.status == TouchScreenKeyboard.Status.Done) {
    27.                     OnSubmit(null);
    28.                     SendTouchScreenKeyboardStatusChanged();
    29.                 }
    30.             }
    31.             base.LateUpdate();
    32.         }
    33.  
    34.     }
    35. }