I am building a deep nested form with Angular2 and FormGroup, currently I have a form such as in a parent controller:
this.orderForm = this.fb.group({
customerSelectForm: this.fb.group({ // create nested formgroup to pass to child
selectTypeahead: ['',
Validators.required],
})
})
Then in a child component I have:
<div class="form-group" [formGroup]="customerSelectForm" *ngIf="customerSelectForm">
<label for="oh-custaccount">Customer Account #</label>
<input class="form-control" type="text"
formControlName="selectTypeahead"
(focusout)=someFunction() />
<p *ngIf="customerSelectForm.controls.selectTypeahead.errors?.required">
Number required!</p>
</div>
Now this child template works fine, and renders an error on screen if there is no input inside the text box. I then back in the parent controller have a submit button:
<button type="submit" class=" btn btn-success" [disabled]="orderForm?.invalid">Submit</button>
Again, this works as expected, and only is enabled after an input is registered in the selectTypeahead input.
Now due to the large nature of this form, I want to have a display next to the submit button, that lists all form elements, which are currently failing. I did try rendering:
{{orderForm.errors}}
But this stayed as "null" even when my form was invalid, how would I list all inputs from orderFrom that have currently not passed/matched their corresponding validation rules?
{{orderForm.errors}}
says null when it's invalid you have some other issue.