I have successfully created a table and a button that generates dynamic rows with inputs inside the table. One issue I'm facing is that when I press enter in the first input, a new row is created (which works), but I can't seem to focus on the new input field. Below is my current implementation:
<input type="text" class="form-control" placeholder="Product Code" formControlName="product_code" tabindex="{{i+1}}" (keyup.enter)="autoProduct($event)">
Here is the relevant code from my .ts file:
autoProduct(event) {
this.addProduct();
if (event.keyCode === 13) {
event.preventDefault();
const inputs =
Array.prototype.slice.call(document.querySelectorAll('input'));
console.log(inputs);
const index =
(inputs.indexOf(document.activeElement) + 1) % inputs.length;
console.log(index);
const input = inputs[index];
console.log(input);
input.focus();
input.select();
}
}
I've looked at solutions on Stack Overflow, but I haven't been able to get it to work. Any assistance would be greatly appreciated.