form invalid event

General discussion and chat (archived)
pmuser2
Hobby Astronomer
Hobby Astronomer
Posts: 26
Joined: 2018-02-09, 04:35

form invalid event

Unread post by pmuser2 » 2018-06-16, 22:43

In HTML 5, 4.10 Forms — 4.10.1.4 Client-side form validation, there has always been the following note:
"When a form is submitted, invalid events are fired at each form control that is invalid, and then at the form element itself."

But browsers actually fire 'invalid' event only at the form control, not at the form itself. Test document:

Code: Select all

<!doctype html><html lang="en"><meta charset="utf-8"><title>title</title>
<form><input name="name" required><input type="submit"></form>
<script>
document.forms[0].addEventListener ('invalid', function (ev)
{
	console.log (ev.target);
}, true);
</script>
Do I understand something incorrectly or browsers ignore HTML in aforementioned part?

(By the way, with that example document we can see that console.log () in IE11 and Edge prints closing 'input' tag.)

Locked