Auto input focusing not working in iOS (works in android) with Cordova











up vote
0
down vote

favorite












I am building an app with Cordova, for both of iOS and Android.



I have a page where I have 3 inputs, each input, will take 1 digit to make a code.



Something like: 123



So in the first input you would type '1', it would jump to the next input and focus on it, so you could type the '2'.
This behaviour works fine in Android!
Same code doesn't seem to work for iOS though.
I have the following html:



<form class="matrixZone">
<div class="CardList optionMenu fullRowInput">
<input class="mb20" type="tel" id="new_auth1" move-next-input ng-model="operation.authorizationCodeConfirm[0]" ng-click="newCodeAutorizationfocus(1)" ng-change="changeFocus(2)" maxlength="1" style="-webkit-text-security: disc; text-security: disc;">
<input class="mb20" type="tel" id="new_auth2" move-next-input ng-model="operation.authorizationCodeConfirm[1]" ng-click="newCodeAutorizationfocus(2)" ng-change="changeFocus(3)" maxlength="1" style="-webkit-text-security: disc; text-security: disc;">
<input class="mb20" type="tel" id="new_auth3" move-next-input ng-model="operation.authorizationCodeConfirm[2]" ng-click="newCodeAutorizationfocus(3)" ng-change="changeFocus(4)" maxlength="1" style="-webkit-text-security: disc; text-security: disc;">
</div>
</form>


For the directive move-next-input I have:



function moveNextInput() {
return {
restrict: 'A',
link: function ($scope, element) {
element.on("input", function (e) {

if (element.val().length == element.attr("maxlength")) {
var $nextElement = element.next();
if ($nextElement.length) {
$nextElement[0].focus();
$nextElement[0].click();
}
}
}).keyup(function (e) {
if (e.which === 8 && !this.value) {
$(this).prev().focus();
$(this).prev().click();

}
});


And I have the following functions as well (on the controller):



$scope.changeFocus = function (n) {
if (n === 0) {
var id = "new_auth3";
var element = $window.document.getElementById(id);
if (element) {
if (isNaN($scope.operation.authorizationCodeConfirm[2]) || $scope.operation.authorizationCodeConfirm[2] == "")
return;
element.blur();
$scope.oldMCCStr = getMCC($scope.operation.authorizationCodeConfirm);
$('#new_auth1').focus
console.log("esta a ser chamado!");
}
}
};


// checks if the key pressed is a number
var checkInput = function (inputArr) {
angular.forEach(inputArr, function (value, key) {
if (null !== inputArr[key]) {
var compare = parseInt(inputArr[key]);

if (isNaN(compare)) {
inputArr[key] = '';
}
}
});
};

$scope.$watch('operation.authorizationCodeConfirm', function (newValue, oldValue) {
checkInput($scope.operation.authorizationCodeConfirm);
console.log("esta a ser chamado!");
}, true);









share|improve this question




























    up vote
    0
    down vote

    favorite












    I am building an app with Cordova, for both of iOS and Android.



    I have a page where I have 3 inputs, each input, will take 1 digit to make a code.



    Something like: 123



    So in the first input you would type '1', it would jump to the next input and focus on it, so you could type the '2'.
    This behaviour works fine in Android!
    Same code doesn't seem to work for iOS though.
    I have the following html:



    <form class="matrixZone">
    <div class="CardList optionMenu fullRowInput">
    <input class="mb20" type="tel" id="new_auth1" move-next-input ng-model="operation.authorizationCodeConfirm[0]" ng-click="newCodeAutorizationfocus(1)" ng-change="changeFocus(2)" maxlength="1" style="-webkit-text-security: disc; text-security: disc;">
    <input class="mb20" type="tel" id="new_auth2" move-next-input ng-model="operation.authorizationCodeConfirm[1]" ng-click="newCodeAutorizationfocus(2)" ng-change="changeFocus(3)" maxlength="1" style="-webkit-text-security: disc; text-security: disc;">
    <input class="mb20" type="tel" id="new_auth3" move-next-input ng-model="operation.authorizationCodeConfirm[2]" ng-click="newCodeAutorizationfocus(3)" ng-change="changeFocus(4)" maxlength="1" style="-webkit-text-security: disc; text-security: disc;">
    </div>
    </form>


    For the directive move-next-input I have:



    function moveNextInput() {
    return {
    restrict: 'A',
    link: function ($scope, element) {
    element.on("input", function (e) {

    if (element.val().length == element.attr("maxlength")) {
    var $nextElement = element.next();
    if ($nextElement.length) {
    $nextElement[0].focus();
    $nextElement[0].click();
    }
    }
    }).keyup(function (e) {
    if (e.which === 8 && !this.value) {
    $(this).prev().focus();
    $(this).prev().click();

    }
    });


    And I have the following functions as well (on the controller):



    $scope.changeFocus = function (n) {
    if (n === 0) {
    var id = "new_auth3";
    var element = $window.document.getElementById(id);
    if (element) {
    if (isNaN($scope.operation.authorizationCodeConfirm[2]) || $scope.operation.authorizationCodeConfirm[2] == "")
    return;
    element.blur();
    $scope.oldMCCStr = getMCC($scope.operation.authorizationCodeConfirm);
    $('#new_auth1').focus
    console.log("esta a ser chamado!");
    }
    }
    };


    // checks if the key pressed is a number
    var checkInput = function (inputArr) {
    angular.forEach(inputArr, function (value, key) {
    if (null !== inputArr[key]) {
    var compare = parseInt(inputArr[key]);

    if (isNaN(compare)) {
    inputArr[key] = '';
    }
    }
    });
    };

    $scope.$watch('operation.authorizationCodeConfirm', function (newValue, oldValue) {
    checkInput($scope.operation.authorizationCodeConfirm);
    console.log("esta a ser chamado!");
    }, true);









    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am building an app with Cordova, for both of iOS and Android.



      I have a page where I have 3 inputs, each input, will take 1 digit to make a code.



      Something like: 123



      So in the first input you would type '1', it would jump to the next input and focus on it, so you could type the '2'.
      This behaviour works fine in Android!
      Same code doesn't seem to work for iOS though.
      I have the following html:



      <form class="matrixZone">
      <div class="CardList optionMenu fullRowInput">
      <input class="mb20" type="tel" id="new_auth1" move-next-input ng-model="operation.authorizationCodeConfirm[0]" ng-click="newCodeAutorizationfocus(1)" ng-change="changeFocus(2)" maxlength="1" style="-webkit-text-security: disc; text-security: disc;">
      <input class="mb20" type="tel" id="new_auth2" move-next-input ng-model="operation.authorizationCodeConfirm[1]" ng-click="newCodeAutorizationfocus(2)" ng-change="changeFocus(3)" maxlength="1" style="-webkit-text-security: disc; text-security: disc;">
      <input class="mb20" type="tel" id="new_auth3" move-next-input ng-model="operation.authorizationCodeConfirm[2]" ng-click="newCodeAutorizationfocus(3)" ng-change="changeFocus(4)" maxlength="1" style="-webkit-text-security: disc; text-security: disc;">
      </div>
      </form>


      For the directive move-next-input I have:



      function moveNextInput() {
      return {
      restrict: 'A',
      link: function ($scope, element) {
      element.on("input", function (e) {

      if (element.val().length == element.attr("maxlength")) {
      var $nextElement = element.next();
      if ($nextElement.length) {
      $nextElement[0].focus();
      $nextElement[0].click();
      }
      }
      }).keyup(function (e) {
      if (e.which === 8 && !this.value) {
      $(this).prev().focus();
      $(this).prev().click();

      }
      });


      And I have the following functions as well (on the controller):



      $scope.changeFocus = function (n) {
      if (n === 0) {
      var id = "new_auth3";
      var element = $window.document.getElementById(id);
      if (element) {
      if (isNaN($scope.operation.authorizationCodeConfirm[2]) || $scope.operation.authorizationCodeConfirm[2] == "")
      return;
      element.blur();
      $scope.oldMCCStr = getMCC($scope.operation.authorizationCodeConfirm);
      $('#new_auth1').focus
      console.log("esta a ser chamado!");
      }
      }
      };


      // checks if the key pressed is a number
      var checkInput = function (inputArr) {
      angular.forEach(inputArr, function (value, key) {
      if (null !== inputArr[key]) {
      var compare = parseInt(inputArr[key]);

      if (isNaN(compare)) {
      inputArr[key] = '';
      }
      }
      });
      };

      $scope.$watch('operation.authorizationCodeConfirm', function (newValue, oldValue) {
      checkInput($scope.operation.authorizationCodeConfirm);
      console.log("esta a ser chamado!");
      }, true);









      share|improve this question















      I am building an app with Cordova, for both of iOS and Android.



      I have a page where I have 3 inputs, each input, will take 1 digit to make a code.



      Something like: 123



      So in the first input you would type '1', it would jump to the next input and focus on it, so you could type the '2'.
      This behaviour works fine in Android!
      Same code doesn't seem to work for iOS though.
      I have the following html:



      <form class="matrixZone">
      <div class="CardList optionMenu fullRowInput">
      <input class="mb20" type="tel" id="new_auth1" move-next-input ng-model="operation.authorizationCodeConfirm[0]" ng-click="newCodeAutorizationfocus(1)" ng-change="changeFocus(2)" maxlength="1" style="-webkit-text-security: disc; text-security: disc;">
      <input class="mb20" type="tel" id="new_auth2" move-next-input ng-model="operation.authorizationCodeConfirm[1]" ng-click="newCodeAutorizationfocus(2)" ng-change="changeFocus(3)" maxlength="1" style="-webkit-text-security: disc; text-security: disc;">
      <input class="mb20" type="tel" id="new_auth3" move-next-input ng-model="operation.authorizationCodeConfirm[2]" ng-click="newCodeAutorizationfocus(3)" ng-change="changeFocus(4)" maxlength="1" style="-webkit-text-security: disc; text-security: disc;">
      </div>
      </form>


      For the directive move-next-input I have:



      function moveNextInput() {
      return {
      restrict: 'A',
      link: function ($scope, element) {
      element.on("input", function (e) {

      if (element.val().length == element.attr("maxlength")) {
      var $nextElement = element.next();
      if ($nextElement.length) {
      $nextElement[0].focus();
      $nextElement[0].click();
      }
      }
      }).keyup(function (e) {
      if (e.which === 8 && !this.value) {
      $(this).prev().focus();
      $(this).prev().click();

      }
      });


      And I have the following functions as well (on the controller):



      $scope.changeFocus = function (n) {
      if (n === 0) {
      var id = "new_auth3";
      var element = $window.document.getElementById(id);
      if (element) {
      if (isNaN($scope.operation.authorizationCodeConfirm[2]) || $scope.operation.authorizationCodeConfirm[2] == "")
      return;
      element.blur();
      $scope.oldMCCStr = getMCC($scope.operation.authorizationCodeConfirm);
      $('#new_auth1').focus
      console.log("esta a ser chamado!");
      }
      }
      };


      // checks if the key pressed is a number
      var checkInput = function (inputArr) {
      angular.forEach(inputArr, function (value, key) {
      if (null !== inputArr[key]) {
      var compare = parseInt(inputArr[key]);

      if (isNaN(compare)) {
      inputArr[key] = '';
      }
      }
      });
      };

      $scope.$watch('operation.authorizationCodeConfirm', function (newValue, oldValue) {
      checkInput($scope.operation.authorizationCodeConfirm);
      console.log("esta a ser chamado!");
      }, true);






      android ios cordova






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 8 at 6:10









      FishSaidNo

      3015




      3015










      asked Nov 7 at 18:38









      Ana Sequeira

      77110




      77110





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53195729%2fauto-input-focusing-not-working-in-ios-works-in-android-with-cordova%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53195729%2fauto-input-focusing-not-working-in-ios-works-in-android-with-cordova%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Academy of Television Arts & Sciences

          L'Équipe

          1995 France bombings