I wrote a special directive to check my form fields. When certain criteria are met (i.e., it is dirty and valid), I want to automatically adjust the focus to the next input element. This is a requirement from my users, so that they can most effectively navigate forms.
A simplified directive is as follows:
directive('custom', ['$parse', function($parse) { return { restrict: 'A', require: ['ngModel', '^ngController'], link: function(scope, element, attrs, ctrls) { var model=ctrls[0], form=ctrls[1]; scope.next = function(){ return model.$valid } scope.$watch(scope.next, function(newValue, oldValue){ if (newValue && model.$dirty){ ??? } })
Now my question is: how can I determine - the next input element (which is the next sibling) or perhaps through tabindex - and focus on it without using jQuery?
It is currently unclear to me how to go to the next input element from the available "scope" or "element" attributes without jQuery; and JQlite does not have a focus method. Basically, I need a working replacement ??? in my code.
Any help is greatly appreciated. thanks JΓΌrgen
source share