tellform/public/modules/forms/directives/on-enter-key.client.directive.js

22 lines
534 B
JavaScript
Raw Normal View History

2016-04-17 02:45:17 +00:00
'use strict';
2016-04-12 02:14:38 +00:00
angular.module('forms').directive('onEnterOrTabKey', ['$rootScope', function($rootScope){
2016-04-12 02:14:38 +00:00
return {
restrict: 'A',
2016-04-12 02:14:38 +00:00
link: function($scope, $element, $attrs) {
2016-04-17 02:45:17 +00:00
$element.bind('keydown keypress', function(event) {
2016-04-12 02:14:38 +00:00
var keyCode = event.which || event.keyCode;
console.log('keyCode is: '+keyCode);
if((keyCode === 13 || keyCode === 9) && !event.shiftKey) {
2016-05-13 23:52:28 +00:00
event.preventDefault();
2016-04-12 02:14:38 +00:00
$rootScope.$apply(function() {
$rootScope.$eval($attrs.onEnterOrTabKey);
2016-04-12 02:14:38 +00:00
});
}
});
}
};
2016-04-12 02:14:38 +00:00
}]);