Автоматическая фокусировка ввода не работает в iOS (работает в Android) с Cordova - PullRequest
0 голосов
/ 07 ноября 2018

Я создаю приложение с Cordova для iOS и Android.

У меня есть страница, где у меня есть 3 входа, каждый из которых займет 1 цифру, чтобы сделать код.

Что-то вроде: 123

Таким образом, в первом входе вы наберете «1», он перейдет к следующему входу и сфокусируется на нем, чтобы вы могли ввести «2». Это поведение прекрасно работает в Android! Тот же код, похоже, не работает для iOS. У меня есть следующий 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>

Для директивы move-next-input у меня есть:

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();

                }
            });

И у меня также есть следующие функции (на контроллере):

$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);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...