request| feat(form): Ability to programmatically submit an AbstractControl, NgForm or a FormGroupDirective #20562
Labels
area: forms
feature: under consideration
Feature request for which voting has completed and the request is now under consideration
feature
Issue that requests a new feature
freq2: medium
state: Needs Design
Milestone
I'm submitting a...
Current behavior
In standard HTML/TypeScript, without angular, it's possible to get a HTMLFormElement and call either
.sumbit()
or.reset()
on it to submit it programmatically. If we want to do this in an Angular2 Component, we will need to either:@ViewChild('myForm') formElementRef
, casting theformElementRef.nativeElement
toHtmlFormElement
and then call.submit()
on itinput type="sumbit"
(or similar), again do a@ViewChild
on it and trigger it programmatically.Note that in the case of
.reset()
this is very well supported and documented.Expected behavior
To be able to trigger the
.submit()
operation directly from anFormGroup
/FormArray
or even anNgForm
would be really helpful.There are cases where, for practical UI/UX reasons the submit button cannot be in the
<form>
element itself. Although this is far from ideal, it's still something that can be and is done.Minimal reproduction of the problem with instructions
`<button #submit>Submit!
[...]`Then try to submit the form without using an
ElementRef
or a hidden submit inside the<form>
.What is the motivation / use case for changing the behavior?
Some UIs will require us to have the submit element outside of the
<form>
, or to submit a form relying on different mechanism/conditions (e.g., time triggered for a game-like UI).Environment
The text was updated successfully, but these errors were encountered: