@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 triedkeyup
orkeydown
but still not working. How can I get this done?Thank you
Posts: 1
Participants: 1