I've built a validation component that works great. However, I'd like to extend it by adding success messages when a form is submitted successfully.
In the component I pass in the form, watch for changes, and act on the error:
this.formGroup.valueChanges.pipe(takeUntil(this.ngUnsubscribe)).subscribe(data => {
if (this.formGroup.invalid) {
this.validation = { message: `Check for errors in the form`, valid: false };
} else {
this.validation = { message: '', valid: true };
}
});
However I can't see a direct way to get a submission event into my component so that I can show success in the ui.
- Can I use the (ngSubmit) event somehow?
- what would you do to get it?
UPDATE:
After significant time invested into this my feature request is here
Wrote about "success handling" on Medium
(2022) we finally have the ng-submitted
class (v12.1)
Sergio Contreras Sustaita :
I don't know any submission event directly from the FormGroup class, what I know is that you should listen it from the form template.\n\n<form [formGroup]=\"formGroup\" (ngSubmit)=\"submit()\">\n <!-- Your controls here-->\n <button>Submit</button>\n</form>\n\n\nIn your component code you should listen the submit event creating the submit() method",
2019-02-13T20:56:10