I've encountered an issue with an AngularJS directive that is supposed to restrict an input field to only accept numbers. Strangely, the directive functions properly in Chrome and Firefox but fails in IE11.
Does anyone know what needs to be added to fix this problem? Or is it possible that directives simply don't work as intended in IE11? Any assistance in finding a workaround or identifying any errors in the code would be highly appreciated.
The version of IE11 I am using is 11.0.9600.19596 - Update Versions: 11.0.170. In this particular version, I am able to type alphabetical characters into the input box, which differs from the behavior observed in Chrome and Firefox.
I also tested it on IE11 Version 11.1392.17763.0 Update Version 11.0.205
Not sure what else to investigate.
Thank you,
Erasmo
AngularJS for onlynum
app.directive('onlyNum', function () {
return function (scope, element, attrs) {
var keyCode = [8, 9, 37, 39, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 110];
element.bind("keydown", function (event) {
console.log($.inArray(event.which, keyCode));
if ($.inArray(event.which, keyCode) == -1) {
scope.$apply(function () {
scope.$eval(attrs.onlyNum);
event.preventDefault();
});
event.preventDefault();
}
});
};
});
HTML:
<div class="w-25 p-3">
<label for="meeting-id">Meeting ID</label>
<input type="number" ng-model="meetingId" id="meeting-id" ng-trim="true" class="form-control" placeholder="Enter Meeting ID" only-num />
</div>