Skip to content

Commit

Permalink
Merge pull request #2973 from bitzesty/form-error-scroll
Browse files Browse the repository at this point in the history
Scroll to first visible error and try to focus
  • Loading branch information
Lubosky authored Jun 20, 2024
2 parents 5c4c704 + 831abc5 commit 76a716d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/views/account/collaborators/_form.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,21 @@
- else
= f.submit "Add the collaborator", class: "govuk-button"
= link_to "Cancel", account_collaborators_path, class: "govuk-button govuk-button--secondary"

javascript:
setTimeout(() => {
const element = document.querySelector('.govuk-form-group--error')
if (element) {
const input = element.querySelector('[aria-invalid="true"]')
const scrollIntoViewOptions = { behavior: 'smooth', block: 'end', inline: 'nearest' }
if (input) {
input.focus()
input.scrollIntoView(scrollIntoViewOptions)
} else {
element.scrollIntoView(scrollIntoViewOptions)
}
}
}, '100')

0 comments on commit 76a716d

Please sign in to comment.