Search Unity

TextMesh Pro Any way to prevent Inputfield from losing focus on tap?

Discussion in 'UGUI & TextMesh Pro' started by BennyTan, Jun 6, 2019.

  1. BennyTan

    BennyTan

    Joined:
    Jan 23, 2014
    Posts:
    141
    Hi,

    I am currently using unity 2019.1.5, Textmesh Pro 2.0.1 and the text mesh pro Input field with "hide mobile input" true and "on focus select all" false.

    For example i am using a multi-line input type, and have typed a long sentence which i now want to edit. I now tap on the input field. What happens is that the editing position/caret appears at the end of the sentence and the soft keyboard appears. However, i want to edit the middle of the sentence and try to tap there. The inputfield loses focus and the soft keyboard closes

    Is there any way to prevent a selected inputfield from becoming losing focus when the tap occurs within the currently focused input field ?

    I know you can tap directly in the middle of the sentence to make the caret appear there, but its a hit or miss situation with no visual indicators and no way to change you edit position after its made, so if you miss and want to try again, you have to tap to lose focus and tap to try again, hoping that the touch is detected at the correct position this time (I have fat fingers).

    In addition, every time you do that, the soft keyboard pops up and down which is doubly annoying.

    Current NATIVE input field behaviour is that the soft keyboard closes only when you close it manually or tap AWAY from the input field, not when you tap on it.
     
    rgonsalv likes this.
  2. vandijckv

    vandijckv

    Joined:
    May 28, 2014
    Posts:
    2
    just here to bump this.
    anybody knows how to solve this issue?
    makes editing multiline text in mobile (testing on android here) impossible.
     
  3. vandijckv

    vandijckv

    Joined:
    May 28, 2014
    Posts:
    2
    I created an adjusted version of the InputField — TextMeshPro, where I commented out every line in which the m_softKeyboard was made inactive, but nothing seems to solve the issue...
     
  4. nimrodbens

    nimrodbens

    Joined:
    Feb 14, 2018
    Posts:
    6
    did you end up solving it? i'm facing a similar issue.
     
  5. VenoliS

    VenoliS

    Joined:
    Jul 29, 2020
    Posts:
    2
    @Unity Please answer somone from unity to this........
     
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I presume this is on Android? If so, please submit a bug report so that we can have the Android team address this behavior since it is Android specific / something that needs to be handle at the Android API level and not TMP / managed code.
     
  7. bakno

    bakno

    Joined:
    Mar 18, 2007
    Posts:
    604
    Trying to solve many mobile input-field issues by using a soft-keyboard and this functionality is necessary.

    On Update, I try to force it with ActivateInputField(), but it jumps back to loosing focus immediately.

    How to solve this?
     
  8. LexaMV

    LexaMV

    Joined:
    Feb 20, 2018
    Posts:
    28
    @Unity Please answer somone from unity to this........
     
  9. chankeiro

    chankeiro

    Joined:
    Oct 25, 2021
    Posts:
    11
    same problem here
     
  10. gisinator

    gisinator

    Joined:
    Jan 23, 2021
    Posts:
    11
    I'm facing the exact same issue. @Unity any chance you have a look after it has been an ongoing issue for over almost 4 years?
     
  11. GXMark

    GXMark

    Joined:
    Oct 13, 2012
    Posts:
    514
    The way i maintain focus on an text mesh pro input is as follows:

    Code (CSharp):
    1. [SerializeField] private TMP_InputField filter;
    2.  
    3. private int _caretPos;
    4.  
    5. private void OnFilterValueChanged(string value)
    6. {
    7.       _caretPos =  = filter.caretPosition;
    8.  
    9.       // Do something here to raise an event e.g. OnTabSelect
    10. }
    11.  
    12. private void OnTabSelect(int index)
    13. {
    14.             filter.ActivateInputField();
    15.             filter.caretPosition = _caretPos ;
    16. }