Use js to set focus on first invalid contact form field.

This commit is contained in:
Fredrik Jonsson 2025-12-01 14:29:54 +01:00
commit 1ae3fd8ab9

View file

@ -31,8 +31,12 @@
{ once: true }, { once: true },
); );
// Mark the form as submitted. form.addEventListener('submit', function (e) {
button.addEventListener('click', () => form.classList.add('js-submitted')); // Set focus on first invalid field.
if (!e.target.validity.valid) {
form.querySelector(':invalid').focus();
}
});
// Display messages. // Display messages.
if (location.search.substring(1) !== '') { if (location.search.substring(1) !== '') {