Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49183

Keypress event not working on Android device

$
0
0

@Akgul wrote:

I have a directive which controls my input value desired formatted or not.

directive('validNumber', function(shareDataService)
 {
      return
      {
        require: 'ngModel',
        link: function(scope, element, attrs, ngModelCtrl)
        {
          if(!ngModelCtrl)
          {
            return;
          }

      ngModelCtrl.$parsers.push(function(val) {
        if (angular.isUndefined(val)) {
            var val = '';
        }
        var clean = val.replace(/[^-0-9\.]/g, '');
		      var decimalCheck  = clean.split('.');
        if(!angular.isUndefined(decimalCheck[1]))
        {
            decimalCheck[1] = decimalCheck[1].slice(0,2);
            clean = decimalCheck[0] + '.' + decimalCheck[1];
        }

        if (val !== clean)
        {
          ngModelCtrl.$setViewValue(clean);
          ngModelCtrl.$render();
        }


        return scope.hesapla(clean);
      });

      element.bind('keypress', function(event) {
        if(event.keyCode === 32) { // space
          event.preventDefault();
        }
      });

      element.bind('keypress', function(event) {
        if(event.keyCode === 45) { // - key
          event.preventDefault();
        }
      });
    }
  };
})

It's working on browser perfectly but keypress event not working on the device.Tried to inspect device with google chrome but not firing. I also tried keyup or keydown but still not working. How can I get this done?

Thank you

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49183

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>