Posted 20 November 2023, 12:24 am EST - Updated 20 November 2023, 12:29 am EST
Hi
I have a flexgrid it has a column which has two inputs input1, input2(optional). on keydown.tab it calls tabEvent().
[code]tabEvent(value: any, type: string, item: any): void {
var index = this.slListItems.indexOf(item);
// Function to find the next enabled input element
const findNextEnabledItem = (startIndex: number, targetType: string): HTMLElement | null => {
let nextItem: HTMLElement | null = null;
if (targetType === 'ea') { nextItem = document.getElementById(`inputcs${this.slListItems[startIndex + 1]?.productId}`); console.log(nextItem.id,'ea') } else if (targetType === 'cs') { nextItem = document.getElementById(`inputea${this.slListItems[startIndex]?.productId}`); console.log(nextItem.id,'cs') if (nextItem == null || nextItem.hasAttribute('disabled')) { // If the 'cs' item is disabled or doesn't exist, check for the next 'cs' item nextItem = document.getElementById(`inputcs${this.slListItems[startIndex + 1]?.productId}`); console.log(nextItem.id,'cs') } } if (nextItem && nextItem.hasAttribute('disabled')) { // If the next item is disabled, recursively find the next enabled item return findNextEnabledItem(startIndex + 1, targetType); } console.log(nextItem.id,'out') return nextItem; }; // Introduce a delay before attempting to find the next item setTimeout(() => { const nextItem = findNextEnabledItem(index, type); console.log(nextItem?.id) if (nextItem) { nextItem.focus(); this.flexGrid?.scrollIntoView(index, -1); } }, 100)
}[/code]
In Html, I have
<input
[(ngModel)]=“cell.item.cartCaseQuantity”
[disabled]=“!cell.item.orderable”
#input1
(keydown.tab=“tabEvent($event,input1.value, ‘cs’, cell.item)”
id=“inputcs{{ cell.item.productId }}”
/>
<input
*ngIf=“cell.item.showQuantity”
#input2
id=“inputea{{ cell.item.productId }}”
[(ngModel)]=“cell.item.cartEachQuantity”
[disabled]=“!cell.item.orderable”
(keydown.tab)=tabEvent($event,input2.value, ‘ea’, cell.item)"
/>
I want to scroll to the flex grid while focusing on inputs while tabbing but it’s breaking. Can you Please suggest.