You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
To prevent double execution of the handler, use only one of the ngSubmit or ngClick directives. This is because of the following form submission rules in the HTML specification:
If a form has only one input field then hitting enter in this field triggers form submit (ngSubmit)
if a form has 2+ input fields and no buttons or input[type=submit] then hitting enter doesn't trigger submit
if a form has one or more input fields and one or more buttons or input[type=submit] then hitting enter in any of the input fields will trigger the click handler on the first button or input[type=submit] (ngClick) and a submit handler on the enclosing form (ngSubmit)
I have made 6 examples, where it should work, but:
The form has one ng-submit directive, and no other nested input[type=button]. Enter should hit the submit() handler, but it doesn't.
Same as #1, but without ng-minlength="1" directive.
This example already has 1 input[type=submit] element, but it does not work both ways — enter key and mouse click.
Same as #3, but ngForm directive is applied to the tag.
Form now has 2 inputs, ngSubmit directive is removed from form and added ngClick directive to the input[type=submit]. Enter key does not work, but ngClick does work.
Same as #5, but input[type=submit] is replaced with <button></button>. Only mouse click works.
Out of 6 examples, only 2 partially work.
The text was updated successfully, but these errors were encountered:
The root problem is that angular does not emulate the behavior of <form> elements when it comes to submitting when you use <ng-form> or <ng-form>. Only real form elements fire the submit event when certain conditions are met. This is simply missing from the implementation. I don't know if it's possible to emulate it completely. Needs quite some event listeners ...
Yup, this is duplicate of #2513. And as explained in #2513 (comment) ngForm was never meant to be used instead of the regular <form> elements but rather inside<form> elements to group controls.
As docs say:
However, on practice it does not work this way: http://plnkr.co/edit/NzPVg60xDyexRQHVvecI?p=preview
I have made 6 examples, where it should work, but:
ng-submit
directive, and no other nestedinput[type=button]
. Enter should hit thesubmit()
handler, but it doesn't.#1
, but withoutng-minlength="1"
directive.input[type=submit]
element, but it does not work both ways —enter
key and mouse click.#3
, butngForm
directive is applied to the tag.ngSubmit
directive is removed from form and addedngClick
directive to theinput[type=submit]
. Enter key does not work, butngClick
does work.#5
, butinput[type=submit]
is replaced with<button></button>
. Only mouse click works.Out of 6 examples, only 2 partially work.
The text was updated successfully, but these errors were encountered: