Files
compras/resources/js/lib/form-error-focus.ts
T
nala eb32c74c56
tests / ci (push) Waiting to run
commit compras1 2811
2026-11-28 07:11:35 +02:00

13 lines
430 B
TypeScript

export function focusFormError(id: string): boolean {
const target = document.getElementById(id);
if (!target) return false;
let ancestor = target.parentElement;
while (ancestor) {
if (ancestor.tagName === 'DETAILS') ancestor.setAttribute('open', '');
ancestor = ancestor.parentElement;
}
target.focus();
target.scrollIntoView({ block: 'center', behavior: 'auto' });
return true;
}