I am building a recursive Reactive Form Using Angular. STACKBLITZ HERE
The form works great as expected. However, since I am building this recursively/dynamically, where the user can build and nest FormArrays and FormGroups infinitely, I am using child components. So far there are 3 main components:
- AppComponent: The main Parent Component
- GroupControlComponent: The child of the parent. Takes care of all the group objects
- ConditionFormComponent: The child of the GroupControlComponent. Takes care of all the conditions within the groups
This is what a basic object looks like:
{
// appcomponent level
"statement": {
//groupcontrol level
"groups": [
{
// conditionform level
"conjunctor": null,
"conditions": [
{
"variable": null
}
],
"groups": []
}
]
}
}
When I set up validation, I want everything to be required. So I went through the FormBuilder, on the parent and children components, and set Validators.required
to true on all form controls.
After going through, I went back and built a form using this approach, and the form returns true always, even when it is not. Is there a way to find if the children are valid on a dynamically created form with child components?
If you'd like to read a little bit more about this specific scenario, here are some other StackOverflow issues going over building and getting the form to work recursively:
Cannot Find Control with Path Using ngIf on Recursive Angular Form
Angular Deeply Nested Reactive Form: Cannot find control with path on nested FormArray