This is a Extended FormBuilder. You can Pass in a Config object and it generates a FormGroup.
npm install ngx-automatic-formbuilderThis is a Extended FormBuilder.
You can Pass in a Config object and it generates a FormGroup.
``sh`
npm i ngx-automatic-formbuilder
import it into Your Module
`ts
import { AutomaticFormbuilderModule } from 'projects/ngx-automatic-formbuilder/src/public-api';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, AutomaticFormbuilderModule],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
`
The config object looks similar to the FormBuilder config
`ts`
export interface IFormSettings {
[key: string]:
| [any, ValidatorFn[]?, AsyncValidatorFn[]?, IExtFormControlSettings?]
| IFormSettings;
}
Get AutomaticFormBuilder via DI and kick it off with your settings
`ts`
constructor(builder: AutomaticFormBuilder) {
this.myForm = builder.setupForm(this.settings);
}
`ts`
settings: IFormSettings = {
user: [
'',
[Validators.required],
[],
{ type: 'text', errormsg: { required: 'User is required!' } }
],
company: {
name: ['', []],
url: ['', []],
address: {
street: [''],
city: [''],
zip: ['']
}
}
};
It can Handle SubGroups as well.
In my example I use this:
You can add the highly needed information to each FormControl to autogenerate the form in your template.
`ts`
export interface IExtFormControl extends FormControl {
errormsg: {
[key: string]: string;
};
type: string;
label: string;
}
And in your template you can use this like this
`html``
Maybe this is helpfull in some way.
I know there are no tests at all.
I will add them by time.