I'm creating wizard with steps. I have two components which has no parent-child relationship:
- Footer component with submit button which is redirecting to the next step.
- Form component which has validation on some inputs.
I created also a service for communication between those 2 components above.
What I want to achieve is to invoke method on footer submit button which will check if form from component number 2 is valid. If yes, we can go to next step, if not, I need to invoke validation errors, without going to next step, until user pass some information to inputs on form.
I'm not sure how can I achieve this. Any thoughts? Thank you.
I have tried to invoke validation on button but in the same form component. It works as expected. Now I would like to invoke this method on submit button in the footer.
This is my onSubmitStep()
method in footer component:
public onSubmitStep() {
if (this.currentStep < this.maxSteps) {
this.currentStep += 1;
this.switchStep();
this.showDefaultFooter = false;
}
}
This is what I have in my form component:
public contractPropertiesContent: ContractPropertiesInput;
public contractPropertiesForm: FormGroup;
constructor(private fb: FormBuilder, private router: Router, private contractPropertiesService: ContractPropertiesService) {}
ngOnInit() {
this.contractPropertiesContent = this.contractPropertiesService.getContractPropertiesContent();
this.contractPropertiesForm = this.initFormGroup();
}
private initFormGroup() {
return this.fb.group({
paymentConditionsInput: ['', Validators.required],
creditDaysInput: ['', Validators.required],
targetInput: ['', Validators.required]
});
}