13 lines
430 B
TypeScript
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;
|
|
}
|