I have created a table and a button which creates dynamic rows inside the table with inputs. When i press enter in the first input i want to create new row (which i have done) but not able to focus in the new input. Here is what I've tried
<input type="text" class="form-control" placeholder="Product Code" formControlName="product_code" tabindex="{{i+1}}" (keyup.enter)="autoProduct($event)">
.ts code:
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 tried this and also this but not able to make it work. Please help.