Use js to set focus on first invalid contact form field.
This commit is contained in:
parent
66c84b8a9b
commit
1ae3fd8ab9
1 changed files with 6 additions and 2 deletions
|
|
@ -31,8 +31,12 @@
|
|||
{ once: true },
|
||||
);
|
||||
|
||||
// Mark the form as submitted.
|
||||
button.addEventListener('click', () => form.classList.add('js-submitted'));
|
||||
form.addEventListener('submit', function (e) {
|
||||
// Set focus on first invalid field.
|
||||
if (!e.target.validity.valid) {
|
||||
form.querySelector(':invalid').focus();
|
||||
}
|
||||
});
|
||||
|
||||
// Display messages.
|
||||
if (location.search.substring(1) !== '') {
|
||||
|
|
|
|||
Loading…
Reference in a new issue