I want to move focus from an input field to another when a user has entered the maxLength amount of characters into the first input field. So in my example below, when a user has entered 2 characters into the day input, the focus would move to the month input.
This is my code so far:
<input formControlName="day" maxlength="2" placeholder="DD" type="text" (keyup)="keytab($event)" />
<input formControlName="month" maxlength="2" placeholder="MM" type="text" (keyup)="keytab($event)" />
<input formControlName="year" maxlength="4" placeholder="YYYY" type="text" />
And in my TS file:
keytab(event){
let nextInput = event.srcElement.nextElementSibling; // get the sibling element
var target = event.target || event.srcElement;
var id = target.id
console.log(id.maxlength); // prints undefined
if(nextInput == null) // check the maxLength from here
return;
else
nextInput.focus(); // focus if not null
}
I know the code in my TS file is wrong, but I was trying to find a way of getting the maxLength property and then shifting the focus. Right now the focus will move as soon as there is a keyup in the input field.
Can anyone tell me how I can access the inputs maxLength property from the keytab function? Thanks.
I'm using Angular 4.
Edit - I'm trying to get the maxLength value and then compare to the input value length. If the input value is more, then move focus to the input field.