- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
export function enterAsTab() {
'ngInject';
let directive = {
restrict: 'A',
link: (scope, element) => {
element.bind('keydown keypress', (event) => {
if(event.which === 13) {
event.preventDefault();
var nextTr = element.next('tr');
var elementToFocus = undefined;
if(nextTr.length){
var inputs = nextTr.find('input');
elementToFocus = inputs[0];
}else{
var parent = element.closest('.modal-body');
var inputs = parent.find('input');
if(inputs.length > 1) {
elementToFocus = inputs[1];
}
}
if(angular.isDefined(elementToFocus)) {
elementToFocus.focus();
elementToFocus.setSelectionRange(0, elementToFocus.value.length)
}else{
}
}
if(event.which > 32) {
if (scope.editingStarted === undefined || scope.editingStarted === false) {
scope.editingStarted = true;
scope.inputElementText = element[0].value;
}
}
if(event.which === 27){//Esc
if(scope.editingStarted === true){
scope.editingStarted = false;
element[0].value = scope.inputElementText;
event.stopPropagation();
}
}
});
}
}
return directive;
}