app .directive('updateOnEnter', function () { return { restrict: 'A', require: 'ngModel', scope: { maxValue: '=ngMax' }, link: function ($scope, element, attrs, ctrl) { element.on("keyup", function (ev) { if (ev.keyCode !== 13) { return ev.stopImmediatePropagation(); } if (parseInt(ctrl.$viewValue) > $scope.maxValue) { ctrl.$viewValue = $scope.maxValue; angular.element(element).val(ctrl.$viewValue) } ctrl.$commitViewValue(); }); } }; });