I have a reactive form of forms. So I need to submit the main form on the last child form submit. Is there a way to do it manually?
<form [formGroup]="form" (ngSubmit)="sendData()">
<form *ngIf="currentQuestion === 1" (submit)="nextQuestion()" formGroupName="nameQuestion"></form>
<form *ngIf="currentQuestion === 3" (submit)="nextQuestion()" formGroupName="phoneQuestion"></form>
<form *ngIf="currentQuestion === 4" (submit)="nextQuestion()" formGroupName="marketsQuestion"></form>
<form *ngIf="currentQuestion === 5" (submit)="nextQuestion()" formGroupName="biographyQuestion"></form>
</form>
CodePudding user response:
Sure, you don't need to use the ngSubmit
if you don't want to. Remove that and add whatever logic you need to your nextQuestion()
method.
<form [formGroup]="form">
<form *ngIf="currentQuestion === 1" (submit)="nextQuestion()" formGroupName="nameQuestion"></form>
<form *ngIf="currentQuestion === 3" (submit)="nextQuestion()" formGroupName="phoneQuestion"></form>
<form *ngIf="currentQuestion === 4" (submit)="nextQuestion()" formGroupName="marketsQuestion"></form>
<form *ngIf="currentQuestion === 5" (submit)="nextQuestion()" formGroupName="biographyQuestion"></form>
</form>
In your component:
nextQuestion(){
...
if (currentQuestion === 5){
this.form.values // Your form values, do what you want with them.
}
}