{"id":27055022,"url":"https://github.com/therealkoedev/automatic-form-builder","last_synced_at":"2025-04-05T09:18:19.292Z","repository":{"id":259004955,"uuid":"338649979","full_name":"TheRealKoeDev/automatic-form-builder","owner":"TheRealKoeDev","description":null,"archived":false,"fork":false,"pushed_at":"2021-03-02T19:52:24.000Z","size":654,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-21T16:57:33.457Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TheRealKoeDev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-13T19:14:52.000Z","updated_at":"2024-10-21T10:43:44.000Z","dependencies_parsed_at":"2024-10-21T16:57:42.258Z","dependency_job_id":null,"html_url":"https://github.com/TheRealKoeDev/automatic-form-builder","commit_stats":null,"previous_names":["therealkoedev/automatic-form-builder"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheRealKoeDev%2Fautomatic-form-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheRealKoeDev%2Fautomatic-form-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheRealKoeDev%2Fautomatic-form-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheRealKoeDev%2Fautomatic-form-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TheRealKoeDev","download_url":"https://codeload.github.com/TheRealKoeDev/automatic-form-builder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247312000,"owners_count":20918344,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-05T09:18:18.704Z","updated_at":"2025-04-05T09:18:19.273Z","avatar_url":"https://github.com/TheRealKoeDev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AutomaticFormBuilder\n\nAutomates [@angular/forms](https://www.npmjs.com/package/@angular/forms) form creation,\nby interpreting the ValidationMetadata from [class-validator](https://www.npmjs.com/package/class-validator).\n\nIt requires the PeerDependencies of @angular/core, @angular/forms, class-transformer and class-validator to be installed to work.\n\n#### Installation\n\n##### npm via git\n\n- npm install `git+https://github.com/TheRealKoeDev/automatic-form-builder.git` @angular/core @angular/forms class-validator class-transformer\n\n\n## Usage\n\n\u003cdetails\u003e\n\u003csummary\u003eImports\u003c/summary\u003e\n    \n```typescript\nimport { FormGroup } from '@angular/forms';\nimport { \n    AutomaticFormBuilder,\n    FormBuildMode,\n    MissingArrayHandling,\n    MissingObjectHandling\n} from 'automatic-form-builder'\nimport { \n    IsArray,\n    IsNotEmpty,\n    IsString,\n    ValidateNested\n} from \"class-validator\";\nimport { \n    Type\n} from \"class-transformer\";\n```\n\u003c/details\u003e\n\u003cdetails\u003e\n\u003csummary\u003eClasses for Usage-Example\u003c/summary\u003e\n    \n```typescript\nclass ChildClass {\n    @IsString()\n    public testPropety: string;\n}\n\nclass ParentClass {\n    // Does not build this property, because it has no Decorator from class-validator \n    public unbuildProperty: unknown;\n    \n    @IsString()\n    public primitiveProperty: string;\n    \n    @IsArray()\n    @IsString({ each: true })\n    public primitiveArrayProperty: string[];\n    \n    @IsNotEmpty()\n    @ValidateNested()\n    @Type(() =\u003e ChildClass)\n    public objectProperty: ChildClass;    \n   \n    @ValidateNested({ each: true })\n    @IsArray()\n    @Type(() =\u003e ChildClass)\n    public objectArrayProperty: ChildClass[];\n}\n```\n\u003c/details\u003e\n\n```typescript\n@Component({\n    selector: 'app-root',\n    templateUrl: './app.component.html',\n    styleUrls: ['./app.component.scss'],\n})\nexport class AppComponent {\n    public form: FormGroup\n    \n    public constructor(automaticFormBuilder: AutomaticFormBuilder){\n        // Builds the whole FormGroup\n        this.form = automaticFormBuilder.build(ParentClass);\n        \n        // Builds the whole FormGroup with the provided data\n        this.form = automaticFormBuilder.build(ParentClass, { primitiveProperty: 'some text' });\n        \n        /**\n         *   Builds the FormGroup for ParentClass with only the control for 'primitiveProperty'\n         **/ \n        this.form = automaticFormBuilder.build(ParentClass, { primitiveProperty: 'some other text' }, {\n            formBuildMode: FormBuildMode.ProvidedDataOnly\n        });\n\n        /**\n         *   Builds the FormGroup for ParentClass with all direct child controls,  \n         *   and writes a FormControl with value null, for ChildArrays and ChildObjects that are not provided in the data.\n         **/ \n        this.form = automaticFormBuilder.build(ParentClass, { }, {\n            formBuildMode: FormBuildMode.ProvidedObjectsOnly,\n            missingObjectHandling: MissingObjectHandling.WriteNull,\n            missingArrayHandling: MissingArrayHandling.WriteNull\n        });\n    }\n}\n\n```\n\n#### Notes \n- You can also specify a custom internal FormBuilder via the token `FORM_BUILDER_TOKEN` if you want to use the builder from [@ng-stack/forms](https://www.npmjs.com/package/@ng-stack/forms) for example.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftherealkoedev%2Fautomatic-form-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftherealkoedev%2Fautomatic-form-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftherealkoedev%2Fautomatic-form-builder/lists"}