Skip to content

request| feat(form): Ability to programmatically submit a SignalForm #71056

Description

@lemoinem

Which @angular/* package(s) are relevant/related to the feature request?

No response

Description

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

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:

  • have a @ViewChild('myForm') formElementRef, casting the formElementRef.nativeElement to HtmlFormElement and then call .submit() on it
  • have a hidden input 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.

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).

Proposed solution

To be able to trigger the .submit() operation directly from SignalForm 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!<button><form [formGroup]="form" (submit)="submitted()">[...]</form>

Then try to submit the form without using an ElementRef or a hidden submit inside the <form>.

Alternatives considered

This was originally #20562 on ReactiveForms, which has been closed because we are moving on from ReactiveForm.
The feature then had over 40 upvotes and was deemed as "the demand is real" (#20562 (comment), by @arturovt).

The advice was to resubmit the feature request against SignalForms. This is that.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: formsforms: signalsneeds: clarificationThis issue needs additional clarification from the reporter before the team can investigate.

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions