Potential bug regarding ng-keyup event on iPads?


#1

I have this function in a controller “ScanCtrl”

$scope.keyup = function(event) {
    if (event.keyCode == 90) {
        $scope.do_scan();
    }

    //failsafe for invalid scans
    if ($scope.scan_value.length >= 20) {
        $scope.do_scan();
    }
    
}

it’s attached to a directive:

app.directive('scan', function() {
    return {
        restrict: 'AE',
        replace: 'true',
        template: '<input id="spt_scan_input" styleX="position: absolute; left: -400px" type="text" ng-keyup="keyup($event)" ng-model="scan_value"/>',
        /*
        link: function(scope, elem, attrs) {
          elem.bind('blur', function() {
              scope.do_scan();
          });
        }
        */
    }
})

and the directive is attached here:

<div ng-repeat="item in scan_queue">
    <a ng-click="go('scan');" class="item item-icon">
        <i class="icon ion-{{item.icon}}"></i>
        <div style="float: right">&gt;&gt;</div>
        <b>{{item.value}}</b>
      </a>
</div>

For some reason, the function refuses to work on an iPad mini native or simulated. I’ve tried using keypressed and keydown, and neither work.

What’s baffling is that the function works perfectly across all Android devices, and the iPhone 6 simulator seems to be able to detect at least when the input field has a length of 20. Has anyone else run into this issue or would anyone know a fix?


#2

I’ve fixed the issue. It turns out that I had a localhost variable that wasn’t initialized properly in the $scope.do_scan().

For some reason, putting alerts inside the keyup function wouldn’t run even before the do_scan() method was called though, leading me to believe that the issue was with keyup as opposed to was was within it. I found the bug through testing on other Android devices as it seemed to handle errors a little more elegantly.