Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

change the focus to next in angular forms

import { Directive, ElementRef, HostListener, Input } from '@angular/core';

@Directive({
selector: '[moveNextByMaxLength]'
})
export class MoveNextByMaxLengthDirective {

constructor(private _el: ElementRef) { }

@HostListener('keyup', ['$event']) onKeyDown(e: any) {
    if (e.srcElement.maxLength === e.srcElement.value.length) {

        e.preventDefault();

        let nextControl: any = e.srcElement.nextElementSibling;
       // Searching for next similar control to set it focus
        while (true)
        {
            if (nextControl)
            {
                if (nextControl.type === e.srcElement.type)
                {
                    nextControl.focus();
                    return;
                }
                else
                {
                    nextControl = nextControl.nextElementSibling;
                }
            }
            else
            {
                return;
            }
        }
    }
}

}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript Passing Function Value as Default Value 
Javascript :: Beep sound Javascript 
Javascript :: Looping arrays with for loop 
Javascript :: difference between w component did update and did mount 
Javascript :: how to use port variable in axios 
Javascript :: combine all ts files into one js 
Javascript :: how to defined an array in js 
Javascript :: add text to innerhtml javascript 
Javascript :: circle collision javascript 
Javascript :: (function (g, d, a) {})(window, document, jQuery); 
Javascript :: javaScript Age in Dog years //write a function that takes your age and returns it to you in dog years - they say that 1 human year is equal to seven dog years function dog Years() javaScript 
Javascript :: money formatting javascript 
Python :: epa meaning 
Python :: matplotlib plot dashed 
Python :: suppress pandas future warnings 
Python :: remove all pyc 
Python :: get the current year in python 
Python :: conda requests 
Python :: get ip from instance id boto3 
Python :: jupyter notebook reload module 
Python :: mypy ignore type 
Python :: python write json to file utf8 
Python :: python letter arr 
Python :: how to make a hidden file in python 
Python :: invert y axis python 
Python :: get text from txt file python 
Python :: hibernate windows with python 
Python :: record the amount of time ittales for code to run python 
Python :: python get full path 
Python :: export dataframe to csv python 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =