Is it possible to tell a mobile device to automatically popup the keyboard for the autofocus element?

StackOverflow https://stackoverflow.com/questions/19888643

  •  30-07-2022
  •  | 
  •  

Domanda

I'm using Meteor and I have a "Add new" button that when clicked, disappears and in its place is a text box.

I won't go into the logic for how it toggles between the button and input as it's quite unrelated. But the HTML code is below.

  1. the bit that toggles between the button and text box

    <tr>
        {{#if isAddNew }}
    
        <td></td>
        <td>{{> insertNewTask }}</td>
    
        {{else}}
        <td></td>
        <td>
            <button id="btnNewTask" class="btn btn-success" role="button">New Task</button>
        </td>
        {{/if}}
    </tr>
    
  2. the insertNewTask template

    <input class="col-xs-9" autofocus="autofocus" placeholder="Enter your new task and press enter"
           id="insertTask" type="text" value="{{name}}"/>
    

Now this all works, the only problem I have is that on a mobile phone, when I hit the Add New Task button, it'll focus on the new input, but I have to click on the input field again in order to get the keyboard to popup.

Is it possible to get the keyboard to automatically pop up?

È stato utile?

Soluzione

On iOS, this possibility is disabled, as iOS designers were worried that web developers would overuse it in a way that's disctracting or confusing to user. I guess on Android it depends on the build, but I won't be surprised if the majority would follow a similar principle.

So in short, no, there's no way to programatically focus on a text field on mobile.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top