0

I found a strange behavior and I can't explain it. My question is if following behavior is a bug or is it documented.

In the following 3 forms only two can be submitted on press enter. The first form doesn't submit on enter key. Why?

function onSubmit() {
    alert('Submit');
}
 First:
 <form onsubmit="onSubmit(); event.preventDefault()">
     <input />
     <input />
 </form>
 Second:
 <form onsubmit="onSubmit(); event.preventDefault()">
     <input />
 </form>
 Third:
 <form onsubmit="onSubmit(); event.preventDefault()">
     <input />
     <input />
     <button></button>
 </form>

A form with only one input works. A form with a button works. But a form with two inputs without buttons doesn't work.

Thomas Sablik
  • 16,127
  • 7
  • 34
  • 62
  • I think that it is HTML related. Please try to add a ` – Arnaud Denoyelle Feb 09 '21 at 22:48
  • @ArnaudDenoyelle I think you could be on right path but the second form doesn't have a button and works. The third form has two inputs and a button (without `type="submit"`) and works. Why? I'll try it without Angular. – Thomas Sablik Feb 09 '21 at 22:49
  • @ArnaudDenoyelle I tried it and it's completely unrelated to Angular. Thank you very much. I'll change the question. – Thomas Sablik Feb 09 '21 at 22:56
  • 1
    @j08691 Thanks. The second dupe contains the answer. It's documented in HTML 2.0. – Thomas Sablik Feb 09 '21 at 23:20
  • just add
    don't forget parntesis
    – HiDd3N Feb 09 '21 at 23:24
  • @HiDd3N That doesn't answer the question. The question is, why the first form isn't submitted but the other two forms are submitted on pressing enter. But the answer is in the second dupe. – Thomas Sablik Feb 09 '21 at 23:37

0 Answers0