Search code examples
iosiphoneionic-frameworkkeyboard

How to go to next input by tapping next key on an iPhone/iPad with Ionic1?


keyboard didn't show next button to jump on next input field. I have tried this solution to do that but didn't work

 <div>        
    <input id="in" class="text-center col-33" type="number" ng-model="ngModel" ng-change="change()" (keyup.enter)="handleLogin()">
    </div>    


handleLogin() {
        e.preventDefault();
        var input = document.getElementById('in');
        input.focus();     
}

can any one have solution for this


Solution

  • If you have two or more input in form and you want the accessoryBar, add this:

    Keyboard.hideFormAccessoryBar(false);
    

    Then you should view the following:

    enter image description here

    With the cursors to go up and down.

    Other thing if you want to change the input from the (keyup.enter)= then you should call the focus() function like I explain next.

    Be sure in your config.xml you have this:

    <preference name="KeyboardDisplayRequiresUserAction" value="false" />
    

    Then call the focus almost like you had done, this idea is from @oroc:

    .factory('focus', function($timeout, $window) {
      return function(id) {
      // timeout makes sure that is invoked after any other event has been triggered.
      // e.g. click events that need to run before the focus or
      // inputs elements that are in a disabled state but are enabled when those events
      // are triggered.
      var element = $window.document.getElementById(id);
      $timeout(function() {
        if(element){
          element.focus();
        }
      });
     };
    })
    

    The key is call with timeout and test, some delay or call multiple times.

    I call focus('') two times to avoid flickering (keyboard hide and then show in half of a second).