0

I need a routine on Ionic that calls the cellphone's Keyboard to an ion-input when entering the page.

An example of a page would be:

<ion-content padding>
  <form>
    <ion-row>
      <ion-col>
        <ion-input #user name="user" type="text" placeholder="Usuário"></ion-input>
      </ion-col>
    </ion-row>
  </form>
</ion-content>

What I want is to use the Navigating Lifecycle from Ionic (I believe that in this case using the ionViewDidEnter) to bring the focus and the Keyboard in the field automatically, I have already tried some codes but unfortunately sometimes it works and sometimes not, thank you right away.

1 Answers1

1

You can set focus in your textarea in the method ionViewDidEnter and show the keyboard by using keyboard plugin of ionic.

@ViewChild('user') input ;

ionicViewDidEnter(){
setTimeout(() => {
      this.input.setFocus();
    },150);
this.keyboard.show();
}

I have referred the following links. Please go through it for more information: https://ionicframework.com/docs/native/keyboard/

https://forum.ionicframework.com/t/setting-focus-to-an-input-in-ionic/62789/4

Set focus on an input with Ionic 2

Shrutika Patil
  • 565
  • 3
  • 18
  • @EvandroG.Santos `this.keyboard.show();` Move this into setTimeout and try again – Shrutika Patil Aug 20 '18 at 06:34
  • I have tried this in my project and I have just set the focus on input , keyboard opens automatically. ionViewDidEnter() { setTimeout(() => { this.searchBar.setFocus(); }, 500) } – Shrutika Patil Sep 25 '18 at 05:32