document.addEventListener('gform/post_render', function (event) {
if (!event.detail || Number(event.detail.formId) !== 4) {
return;
}
const form = document.querySelector('#gform_4');
if (!form) {
return;
}
const summary = form.querySelector('.gform_validation_errors');
if (!summary) {
return;
}
/*
* Make the validation notice programmatically focusable
* and announce it to assistive technology.
*/
summary.setAttribute('tabindex', '-1');
summary.setAttribute('role', 'alert');
summary.setAttribute('aria-live', 'assertive');
/*
* Wait until Gravity Forms and the browser finish their own
* validation/render handling, then bring the notification into view.
*/
setTimeout(function () {
summary.focus({
preventScroll: true
});
const y =
summary.getBoundingClientRect().top +
window.pageYOffset -
120;
window.scrollTo({
top: y,
behavior: 'smooth'
});
}, 150);
});