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;
}
}
}
}
}
Also in JavaScript:
- print("Google") in JavaScript
- difference between React Native and React
- js random minus
- Regular expression: Match everything after a particular word
- html get selected option javascript
- transition event listener does not work
- gatsby guess
- javascript replace text within dom
- install json server with yarn
- arithmetic expressions in scheme
- replace all occurrences of a string in javascript
- how to remove key value pair from object js
- how to shuffle an array javascript
- js insert in array
- console.log in jsx
- import fs node js
- javascript typeof shows object
- ajax file upload from modal
- jquery set title attribute
- vue router implementation
- js start with
- f string javascript
- jquery style display
- sticky operations in javascript