Hello Stack Overflow Community I hope you are having a great day, today I have an issue that I have been trying to figure out and I hope you can tell me how it is done.
Story
I'm trying to create a form with dynamic fields, meaning the form doesn't have defined FormControls, Validators, or anything.
It only has the fields that are active on the form when the form is submitted.\
Ex.
<child-component *ngIf="condition" ngModel ngDefaultControl></child-component>
Is now active and is in the NgForm object and can be sent to the database.
or
Is now not active and is not in the NgForm object and can then not be sent to the database.
The rest of the active fields are then in the object but not the deactivated <child-component>.
I have gotten this to work, however, I'm trying to add " error handling" to the <child-component> to check if the field is empty if it is required and if it is of the type that it is supposed to be Ex. number, text, etc.
I have issues with getting the " error handling" to work.
Question
How do I add an error to my <child-component> if it is required and empty or if the value of the <child-component> input is not of the same type as the input?
Link to StackBlitz (doesn't open in a new window)
Thank you for taking the time to help me out.
Best regards,
Alexander