So, I have my Client class in TypeScript, let's say I have:
export class Client {
id: string = '';
name: string = '';
email: string = '';
}
Now every time I want to create a new Client I need a form, that's how I build it:
this.currentClient = new FormGroup({
id: new FormControl(null, Validators.required),
name: new FormControl(null, Validators.required),
email: new FormControl(false)
}
Then I add the form to the html:
<form [formGroup]="currentClient" (submit)="submit($event)">
<div class="form-group">
<input type="text" formControlName="id" class="form-control" placeholder="Id">
</div>
<div class="form-group">
<input type="text" formControlName="name" class="form-control" placeholder="Name">
</div>
<div class="form-group">
<input type="text" formControlName="email" class="form-control" placeholder="Email">
</div>
<button [disabled]="currentContragent.invalid" class="btn btn-primary" type="submit">Submit</button>
</form>
That's fine but I have some really big classes with more than 30 fields inside. For each, I have to create a TS class, a form group and I have to add it to the html. Is there anything like:
this.currentClient = formGroupFromType(typeof(Client));
And then something that could automatically generate my html using ng-for or something?
I was thinking of building my own class that could hold property name, type, default value, isRequired and some other information like what editor (textbox, numeric textbox, etc). Having a list of properties defined like this could be used to generate the form group and the html, but it won't be strongly typed as I don't see how it could be connected to the Client class.
Any ideas or suggestions?