0

I used this directive from stack overflow but this doesn't work on chosen directive. How can I perform this function on another directive?

module.directive("nextFocus", function () {
    var directive = {
        restrict: 'A',
        link: function (scope, elem, attrs) {
            elem.bind('keydown', function (e) {
                var code = e.keyCode || e.which;
                if (code === 13) {
                    try {
                        if (attrs.tabindex != undefined) {
                            var currentTabIndex = attrs.tabindex;
                            var nextTabIndex = parseInt(attrs.tabindex) + 1;
                            $("[tabindex=" + nextTabIndex + "]").focus();
                        }
                    } catch (e) {

                    }
                }
            });
        }
    };
    return directive;
});
CDspace
  • 2,639
  • 18
  • 30
  • 36
nkota
  • 555
  • 1
  • 6
  • 15
  • Not a good idea. For example the user will be unable to create linebreaks in textareas. – lin Feb 25 '17 at 09:28
  • yah, you are right, in textareas it can be managed by Ctrl + Enter key... – nkota Feb 25 '17 at 10:00
  • Its not a good approach to mix jQuery with AngularJS - please check http://stackoverflow.com/questions/14994391/thinking-in-angularjs-if-i-have-a-jquery-background. You should kick jQuery IMO. Now back to your problem. The diretive is working, right? Now you want to performan this directive on an other directive? Could you create a plnkr or fiddle example on how you tried it? – lin Feb 25 '17 at 10:03

0 Answers0