{
// A section expanded in this same round-trip (see vehicle-expand) is
// still animating open via x-collapse, so its errors read as hidden on
// the first pass. Retry briefly before settling for whatever is visible.
const all = () => [...document.querySelectorAll('[data-error]')];
const findVisible = () => all().find(node => node.offsetParent !== null);
let attempts = 0;
const scroll = () => {
const el = findVisible();
if (el) {
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
return;
}
if (++attempts < 10) {
setTimeout(scroll, 50);
return;
}
// Safety net for a validation rule that outlives the x-show condition
// guarding its field: the submit is blocked by an error the customer
// cannot see or fix. Surface it instead of leaving the button inert.
if (all().length > 0) {
hasUnreachableError = true;
$refs.submit?.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
};
scroll();
})
"
>