James Griess
James Griess

Reputation: 71

Ionic 2 Prompt Alert focus on text input

I am creating an ionic 2 application for android and ios. I have an alert controller that prompts the user for a text input, however when the alert pops up I would like the keyboard to focus on the input, and for the placeholder text to be highlighted. Currently you must tap on the text input for the keyboard to pop up. Is this possible to implement?

here is my alert controller code:

let prompt = this.alertCtrl.create({
    title: this.name,
    message: this.nameMessage,
    inputs: [
      {
        name: 'name',
        placeholder: this.name
      },
    ],
    buttons: [
      {
        text: this.save,
        handler: data => {
          resolve(data.name);
        }
      }
    ],
    enableBackdropDismiss: false
  });
  prompt.present();

Upvotes: 3

Views: 1997

Answers (1)

user8539302
user8539302

Reputation: 51

This is my solution.

First

inputs: [
    {
      id: "autofocu",
      ......
    }
  ],

And then

alert.present()
.then(() => {
  document.getElementById('autofocu').focus();
})
.catch()

Upvotes: 5

Related Questions