Hi everyone, what you need to do is to identify all inputs, text fields and selectors, as well as when opening the key. Move to the next field.
app.directive('focusNext', function () {
return {
restrict: 'A',
link: function ($scope, element, attrs) {
element.bind('keydown', function(e) {
var code = e.keyCode || e.which;
if (code === 13) {
e.preventDefault();
var pageElements = document.querySelectorAll('input, select, textarea'),
element = e.srcElement
focusNext = false,
len = pageElements.length;
for (var i = 0; i < len; i++) {
var elem = pageElements[i];
if (focusNext) {
if (elem.style.display !== 'none') {
elem.focus();
break;
}
} else if (elem === e.srcElement) {
focusNext = true;
}
}
}
});
}
} })
Hope this helps.
source
share