├── .DS_Store ├── .editorconfig ├── README.md ├── angular.json ├── e2e ├── protractor.conf.js ├── src │ ├── app.e2e-spec.ts │ └── app.po.ts └── tsconfig.e2e.json ├── package-lock.json ├── package.json ├── src ├── .DS_Store ├── app │ ├── app.component.css │ ├── app.component.html │ ├── app.component.spec.ts │ ├── app.component.ts │ ├── app.module.ts │ ├── components │ │ ├── button │ │ │ └── button.component.ts │ │ ├── checkbox │ │ │ └── checkbox.component.ts │ │ ├── date │ │ │ └── date.component.ts │ │ ├── dynamic-field │ │ │ └── dynamic-field.directive.ts │ │ ├── dynamic-form │ │ │ └── dynamic-form.component.ts │ │ ├── input │ │ │ └── input.component.ts │ │ ├── radiobutton │ │ │ └── radiobutton.component.ts │ │ └── select │ │ │ └── select.component.ts │ ├── field.interface.ts │ ├── material.module.spec.ts │ └── material.module.ts ├── assets │ └── .gitkeep ├── browserslist ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── index.html ├── karma.conf.js ├── main.ts ├── polyfills.ts ├── styles.css ├── test.ts ├── tsconfig.app.json ├── tsconfig.spec.json └── tslint.json ├── tsconfig.json └── tslint.json /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bahurudeen/dynamicform/9e362854d9e422d4e3c3060fbd04ed0156b2b4f9/.DS_Store -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DynamicForm 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 6.0.0. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 24 | 25 | ## Further help 26 | 27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 28 | # angular_dynamicform 29 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "dynamic-form": { 7 | "root": "", 8 | "sourceRoot": "src", 9 | "projectType": "application", 10 | "prefix": "app", 11 | "schematics": {}, 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/dynamic-form", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "src/tsconfig.app.json", 21 | "assets": [ 22 | "src/favicon.ico", 23 | "src/assets" 24 | ], 25 | "styles": [ 26 | { 27 | "input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css" 28 | }, 29 | "src/styles.css" 30 | ], 31 | "scripts": [] 32 | }, 33 | "configurations": { 34 | "production": { 35 | "fileReplacements": [ 36 | { 37 | "replace": "src/environments/environment.ts", 38 | "with": "src/environments/environment.prod.ts" 39 | } 40 | ], 41 | "optimization": true, 42 | "outputHashing": "all", 43 | "sourceMap": false, 44 | "extractCss": true, 45 | "namedChunks": false, 46 | "aot": true, 47 | "extractLicenses": true, 48 | "vendorChunk": false, 49 | "buildOptimizer": true 50 | } 51 | } 52 | }, 53 | "serve": { 54 | "builder": "@angular-devkit/build-angular:dev-server", 55 | "options": { 56 | "browserTarget": "dynamic-form:build" 57 | }, 58 | "configurations": { 59 | "production": { 60 | "browserTarget": "dynamic-form:build:production" 61 | } 62 | } 63 | }, 64 | "extract-i18n": { 65 | "builder": "@angular-devkit/build-angular:extract-i18n", 66 | "options": { 67 | "browserTarget": "dynamic-form:build" 68 | } 69 | }, 70 | "test": { 71 | "builder": "@angular-devkit/build-angular:karma", 72 | "options": { 73 | "main": "src/test.ts", 74 | "polyfills": "src/polyfills.ts", 75 | "tsConfig": "src/tsconfig.spec.json", 76 | "karmaConfig": "src/karma.conf.js", 77 | "styles": [ 78 | { 79 | "input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css" 80 | }, 81 | "styles.css" 82 | ], 83 | "scripts": [], 84 | "assets": [ 85 | "src/favicon.ico", 86 | "src/assets" 87 | ] 88 | } 89 | }, 90 | "lint": { 91 | "builder": "@angular-devkit/build-angular:tslint", 92 | "options": { 93 | "tsConfig": [ 94 | "src/tsconfig.app.json", 95 | "src/tsconfig.spec.json" 96 | ], 97 | "exclude": [ 98 | "**/node_modules/**" 99 | ] 100 | } 101 | } 102 | } 103 | }, 104 | "dynamic-form-e2e": { 105 | "root": "e2e/", 106 | "projectType": "application", 107 | "architect": { 108 | "e2e": { 109 | "builder": "@angular-devkit/build-angular:protractor", 110 | "options": { 111 | "protractorConfig": "e2e/protractor.conf.js", 112 | "devServerTarget": "dynamic-form:serve" 113 | } 114 | }, 115 | "lint": { 116 | "builder": "@angular-devkit/build-angular:tslint", 117 | "options": { 118 | "tsConfig": "e2e/tsconfig.e2e.json", 119 | "exclude": [ 120 | "**/node_modules/**" 121 | ] 122 | } 123 | } 124 | } 125 | } 126 | }, 127 | "defaultProject": "dynamic-form" 128 | } -------------------------------------------------------------------------------- /e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './src/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | onPrepare() { 23 | require('ts-node').register({ 24 | project: require('path').join(__dirname, './tsconfig.e2e.json') 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; -------------------------------------------------------------------------------- /e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | 3 | describe('workspace-project App', () => { 4 | let page: AppPage; 5 | 6 | beforeEach(() => { 7 | page = new AppPage(); 8 | }); 9 | 10 | it('should display welcome message', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('Welcome to app!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dynamic-form", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "^6.0.0", 15 | "@angular/cdk": "^6.2.0", 16 | "@angular/common": "^6.0.0", 17 | "@angular/compiler": "^6.0.0", 18 | "@angular/core": "^6.0.0", 19 | "@angular/forms": "^6.0.0", 20 | "@angular/http": "^6.0.0", 21 | "@angular/material": "^6.2.1", 22 | "@angular/material-moment-adapter": "^6.2.1", 23 | "@angular/platform-browser": "^6.0.0", 24 | "@angular/platform-browser-dynamic": "^6.0.0", 25 | "@angular/router": "^6.0.0", 26 | "core-js": "^2.5.4", 27 | "moment": "^2.22.2", 28 | "rxjs": "^6.0.0", 29 | "zone.js": "^0.8.26" 30 | }, 31 | "devDependencies": { 32 | "@angular/compiler-cli": "^6.0.0", 33 | "@angular-devkit/build-angular": "~0.6.0", 34 | "typescript": "~2.7.2", 35 | "@angular/cli": "~6.0.0", 36 | "@angular/language-service": "^6.0.0", 37 | "@types/jasmine": "~2.8.6", 38 | "@types/jasminewd2": "~2.0.3", 39 | "@types/node": "~8.9.4", 40 | "codelyzer": "~4.2.1", 41 | "jasmine-core": "~2.99.1", 42 | "jasmine-spec-reporter": "~4.2.1", 43 | "karma": "~1.7.1", 44 | "karma-chrome-launcher": "~2.2.0", 45 | "karma-coverage-istanbul-reporter": "~1.4.2", 46 | "karma-jasmine": "~1.1.1", 47 | "karma-jasmine-html-reporter": "^0.2.2", 48 | "protractor": "~5.3.0", 49 | "ts-node": "~5.0.1", 50 | "tslint": "~5.9.1" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bahurudeen/dynamicform/9e362854d9e422d4e3c3060fbd04ed0156b2b4f9/src/.DS_Store -------------------------------------------------------------------------------- /src/app/app.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bahurudeen/dynamicform/9e362854d9e422d4e3c3060fbd04ed0156b2b4f9/src/app/app.component.css -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

4 | Registration Form 5 |

6 |
7 | 8 | 9 |
10 | {{ form.value | json }} 11 |
12 |
13 | -------------------------------------------------------------------------------- /src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { AppComponent } from './app.component'; 3 | describe('AppComponent', () => { 4 | beforeEach(async(() => { 5 | TestBed.configureTestingModule({ 6 | declarations: [ 7 | AppComponent 8 | ], 9 | }).compileComponents(); 10 | })); 11 | it('should create the app', async(() => { 12 | const fixture = TestBed.createComponent(AppComponent); 13 | const app = fixture.debugElement.componentInstance; 14 | expect(app).toBeTruthy(); 15 | })); 16 | it(`should have as title 'app'`, async(() => { 17 | const fixture = TestBed.createComponent(AppComponent); 18 | const app = fixture.debugElement.componentInstance; 19 | expect(app.title).toEqual('app'); 20 | })); 21 | it('should render title in a h1 tag', async(() => { 22 | const fixture = TestBed.createComponent(AppComponent); 23 | fixture.detectChanges(); 24 | const compiled = fixture.debugElement.nativeElement; 25 | expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!'); 26 | })); 27 | }); 28 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, ViewChild } from "@angular/core"; 2 | import { Validators } from "@angular/forms"; 3 | import { FieldConfig } from "./field.interface"; 4 | import { DynamicFormComponent } from "./components/dynamic-form/dynamic-form.component"; 5 | 6 | @Component({ 7 | selector: "app-root", 8 | templateUrl: "./app.component.html", 9 | styleUrls: ["./app.component.css"] 10 | }) 11 | export class AppComponent { 12 | @ViewChild(DynamicFormComponent) form: DynamicFormComponent; 13 | regConfig: FieldConfig[] = [ 14 | { 15 | type: "input", 16 | label: "Username", 17 | inputType: "text", 18 | name: "name", 19 | validations: [ 20 | { 21 | name: "required", 22 | validator: Validators.required, 23 | message: "Name Required" 24 | }, 25 | { 26 | name: "pattern", 27 | validator: Validators.pattern("^[a-zA-Z]+$"), 28 | message: "Accept only text" 29 | } 30 | ] 31 | }, 32 | { 33 | type: "input", 34 | label: "Email Address", 35 | inputType: "email", 36 | name: "email", 37 | validations: [ 38 | { 39 | name: "required", 40 | validator: Validators.required, 41 | message: "Email Required" 42 | }, 43 | { 44 | name: "pattern", 45 | validator: Validators.pattern( 46 | "^[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,4}$" 47 | ), 48 | message: "Invalid email" 49 | } 50 | ] 51 | }, 52 | { 53 | type: "input", 54 | label: "Password", 55 | inputType: "password", 56 | name: "password", 57 | validations: [ 58 | { 59 | name: "required", 60 | validator: Validators.required, 61 | message: "Password Required" 62 | } 63 | ] 64 | }, 65 | { 66 | type: "radiobutton", 67 | label: "Gender", 68 | name: "gender", 69 | options: ["Male", "Female"], 70 | value: "Male" 71 | }, 72 | { 73 | type: "date", 74 | label: "DOB", 75 | name: "dob", 76 | validations: [ 77 | { 78 | name: "required", 79 | validator: Validators.required, 80 | message: "Date of Birth Required" 81 | } 82 | ] 83 | }, 84 | { 85 | type: "select", 86 | label: "Country", 87 | name: "country", 88 | value: "UK", 89 | options: ["India", "UAE", "UK", "US"] 90 | }, 91 | { 92 | type: "checkbox", 93 | label: "Accept Terms", 94 | name: "term", 95 | value: true 96 | }, 97 | { 98 | type: "button", 99 | label: "Save" 100 | } 101 | ]; 102 | 103 | submit(value: any) {} 104 | } 105 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from "@angular/platform-browser"; 2 | import { NgModule } from "@angular/core"; 3 | 4 | import { AppComponent } from "./app.component"; 5 | import { BrowserAnimationsModule } from "@angular/platform-browser/animations"; 6 | import { MaterialModule } from "./material.module"; 7 | import { FormsModule, ReactiveFormsModule } from "@angular/forms"; 8 | import { InputComponent } from "./components/input/input.component"; 9 | import { ButtonComponent } from "./components/button/button.component"; 10 | import { SelectComponent } from "./components/select/select.component"; 11 | import { DateComponent } from "./components/date/date.component"; 12 | import { RadiobuttonComponent } from "./components/radiobutton/radiobutton.component"; 13 | import { CheckboxComponent } from "./components/checkbox/checkbox.component"; 14 | import { DynamicFieldDirective } from "./components/dynamic-field/dynamic-field.directive"; 15 | import { DynamicFormComponent } from "./components/dynamic-form/dynamic-form.component"; 16 | 17 | @NgModule({ 18 | declarations: [ 19 | AppComponent, 20 | InputComponent, 21 | ButtonComponent, 22 | SelectComponent, 23 | DateComponent, 24 | RadiobuttonComponent, 25 | CheckboxComponent, 26 | DynamicFieldDirective, 27 | DynamicFormComponent 28 | ], 29 | imports: [ 30 | BrowserModule, 31 | BrowserAnimationsModule, 32 | MaterialModule, 33 | ReactiveFormsModule, 34 | FormsModule 35 | ], 36 | providers: [], 37 | bootstrap: [AppComponent], 38 | entryComponents: [ 39 | InputComponent, 40 | ButtonComponent, 41 | SelectComponent, 42 | DateComponent, 43 | RadiobuttonComponent, 44 | CheckboxComponent 45 | ] 46 | }) 47 | export class AppModule {} 48 | -------------------------------------------------------------------------------- /src/app/components/button/button.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from "@angular/core"; 2 | import { FormGroup } from "@angular/forms"; 3 | import { FieldConfig } from "../../field.interface"; 4 | @Component({ 5 | selector: "app-button", 6 | template: ` 7 |
8 | 9 |
10 | `, 11 | styles: [] 12 | }) 13 | export class ButtonComponent implements OnInit { 14 | field: FieldConfig; 15 | group: FormGroup; 16 | constructor() {} 17 | ngOnInit() {} 18 | } 19 | -------------------------------------------------------------------------------- /src/app/components/checkbox/checkbox.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from "@angular/core"; 2 | import { FormGroup } from "@angular/forms"; 3 | import { FieldConfig } from "../../field.interface"; 4 | @Component({ 5 | selector: "app-checkbox", 6 | template: ` 7 |
8 | {{field.label}} 9 |
10 | `, 11 | styles: [] 12 | }) 13 | export class CheckboxComponent implements OnInit { 14 | field: FieldConfig; 15 | group: FormGroup; 16 | constructor() {} 17 | ngOnInit() {} 18 | } 19 | -------------------------------------------------------------------------------- /src/app/components/date/date.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from "@angular/core"; 2 | import { FormGroup } from "@angular/forms"; 3 | import { FieldConfig } from "../../field.interface"; 4 | @Component({ 5 | selector: "app-date", 6 | template: ` 7 | 8 | 9 | 10 | 11 | 12 | 13 | {{validation.message}} 14 | 15 | 16 | `, 17 | styles: [] 18 | }) 19 | export class DateComponent implements OnInit { 20 | field: FieldConfig; 21 | group: FormGroup; 22 | constructor() {} 23 | ngOnInit() {} 24 | } 25 | -------------------------------------------------------------------------------- /src/app/components/dynamic-field/dynamic-field.directive.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ComponentFactoryResolver, 3 | ComponentRef, 4 | Directive, 5 | Input, 6 | OnInit, 7 | ViewContainerRef 8 | } from "@angular/core"; 9 | import { FormGroup } from "@angular/forms"; 10 | import { FieldConfig } from "../../field.interface"; 11 | import { InputComponent } from "../input/input.component"; 12 | import { ButtonComponent } from "../button/button.component"; 13 | import { SelectComponent } from "../select/select.component"; 14 | import { DateComponent } from "../date/date.component"; 15 | import { RadiobuttonComponent } from "../radiobutton/radiobutton.component"; 16 | import { CheckboxComponent } from "../checkbox/checkbox.component"; 17 | 18 | const componentMapper = { 19 | input: InputComponent, 20 | button: ButtonComponent, 21 | select: SelectComponent, 22 | date: DateComponent, 23 | radiobutton: RadiobuttonComponent, 24 | checkbox: CheckboxComponent 25 | }; 26 | @Directive({ 27 | selector: "[dynamicField]" 28 | }) 29 | export class DynamicFieldDirective implements OnInit { 30 | @Input() field: FieldConfig; 31 | @Input() group: FormGroup; 32 | componentRef: any; 33 | constructor( 34 | private resolver: ComponentFactoryResolver, 35 | private container: ViewContainerRef 36 | ) {} 37 | ngOnInit() { 38 | const factory = this.resolver.resolveComponentFactory( 39 | componentMapper[this.field.type] 40 | ); 41 | this.componentRef = this.container.createComponent(factory); 42 | this.componentRef.instance.field = this.field; 43 | this.componentRef.instance.group = this.group; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/app/components/dynamic-form/dynamic-form.component.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Component, 3 | EventEmitter, 4 | Input, 5 | OnChanges, 6 | OnInit, 7 | Output 8 | } from "@angular/core"; 9 | import { 10 | FormGroup, 11 | FormBuilder, 12 | Validators, 13 | FormControl 14 | } from "@angular/forms"; 15 | import { FieldConfig, Validator } from "../../field.interface"; 16 | 17 | @Component({ 18 | exportAs: "dynamicForm", 19 | selector: "dynamic-form", 20 | template: ` 21 |
22 | 23 | 24 |
25 | `, 26 | styles: [] 27 | }) 28 | export class DynamicFormComponent implements OnInit { 29 | @Input() fields: FieldConfig[] = []; 30 | 31 | @Output() submit: EventEmitter = new EventEmitter(); 32 | 33 | form: FormGroup; 34 | 35 | get value() { 36 | return this.form.value; 37 | } 38 | constructor(private fb: FormBuilder) {} 39 | 40 | ngOnInit() { 41 | this.form = this.createControl(); 42 | } 43 | 44 | onSubmit(event: Event) { 45 | event.preventDefault(); 46 | event.stopPropagation(); 47 | if (this.form.valid) { 48 | this.submit.emit(this.form.value); 49 | } else { 50 | this.validateAllFormFields(this.form); 51 | } 52 | } 53 | 54 | createControl() { 55 | const group = this.fb.group({}); 56 | this.fields.forEach(field => { 57 | if (field.type === "button") return; 58 | const control = this.fb.control( 59 | field.value, 60 | this.bindValidations(field.validations || []) 61 | ); 62 | group.addControl(field.name, control); 63 | }); 64 | return group; 65 | } 66 | 67 | bindValidations(validations: any) { 68 | if (validations.length > 0) { 69 | const validList = []; 70 | validations.forEach(valid => { 71 | validList.push(valid.validator); 72 | }); 73 | return Validators.compose(validList); 74 | } 75 | return null; 76 | } 77 | 78 | validateAllFormFields(formGroup: FormGroup) { 79 | Object.keys(formGroup.controls).forEach(field => { 80 | const control = formGroup.get(field); 81 | control.markAsTouched({ onlySelf: true }); 82 | }); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/app/components/input/input.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from "@angular/core"; 2 | import { FormGroup } from "@angular/forms"; 3 | import { FieldConfig } from "../../field.interface"; 4 | @Component({ 5 | selector: "app-input", 6 | template: ` 7 | 8 | 9 | 10 | {{validation.message}} 11 | 12 | 13 | `, 14 | styles: [] 15 | }) 16 | export class InputComponent implements OnInit { 17 | field: FieldConfig; 18 | group: FormGroup; 19 | constructor() {} 20 | ngOnInit() {} 21 | } 22 | -------------------------------------------------------------------------------- /src/app/components/radiobutton/radiobutton.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from "@angular/core"; 2 | import { FormGroup } from "@angular/forms"; 3 | import { FieldConfig } from "../../field.interface"; 4 | @Component({ 5 | selector: "app-radiobutton", 6 | template: ` 7 |
8 | 9 | 10 | {{item}} 11 | 12 |
13 | `, 14 | styles: [] 15 | }) 16 | export class RadiobuttonComponent implements OnInit { 17 | field: FieldConfig; 18 | group: FormGroup; 19 | constructor() {} 20 | ngOnInit() {} 21 | } 22 | -------------------------------------------------------------------------------- /src/app/components/select/select.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from "@angular/core"; 2 | import { FormGroup } from "@angular/forms"; 3 | import { FieldConfig } from "../../field.interface"; 4 | @Component({ 5 | selector: "app-select", 6 | template: ` 7 | 8 | 9 | {{item}} 10 | 11 | 12 | `, 13 | styles: [] 14 | }) 15 | export class SelectComponent implements OnInit { 16 | field: FieldConfig; 17 | group: FormGroup; 18 | constructor() {} 19 | ngOnInit() {} 20 | } 21 | -------------------------------------------------------------------------------- /src/app/field.interface.ts: -------------------------------------------------------------------------------- 1 | export interface Validator { 2 | name: string; 3 | validator: any; 4 | message: string; 5 | } 6 | export interface FieldConfig { 7 | label?: string; 8 | name?: string; 9 | inputType?: string; 10 | options?: string[]; 11 | collections?: any; 12 | type: string; 13 | value?: any; 14 | validations?: Validator[]; 15 | } 16 | -------------------------------------------------------------------------------- /src/app/material.module.spec.ts: -------------------------------------------------------------------------------- 1 | import { MaterialModule } from './material.module'; 2 | 3 | describe('MaterialModule', () => { 4 | let materialModule: MaterialModule; 5 | 6 | beforeEach(() => { 7 | materialModule = new MaterialModule(); 8 | }); 9 | 10 | it('should create an instance', () => { 11 | expect(materialModule).toBeTruthy(); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /src/app/material.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from "@angular/core"; 2 | import { CommonModule } from "@angular/common"; 3 | import { MatMomentDateModule } from "@angular/material-moment-adapter"; 4 | import { 5 | MatButtonModule, 6 | MatIconModule, 7 | MatCardModule, 8 | MatFormFieldModule, 9 | MatInputModule, 10 | MatListModule, 11 | MatDatepickerModule, 12 | MatNativeDateModule, 13 | MatSelectModule, 14 | MatOptionModule, 15 | MatCheckboxModule, 16 | MatRadioModule 17 | } from "@angular/material"; 18 | 19 | @NgModule({ 20 | imports: [ 21 | MatButtonModule, 22 | MatIconModule, 23 | MatCardModule, 24 | MatFormFieldModule, 25 | MatInputModule, 26 | MatListModule, 27 | MatDatepickerModule, 28 | MatNativeDateModule, 29 | MatMomentDateModule, 30 | MatSelectModule, 31 | MatOptionModule, 32 | MatCheckboxModule, 33 | MatRadioModule 34 | ], 35 | exports: [ 36 | MatButtonModule, 37 | MatIconModule, 38 | MatCardModule, 39 | MatFormFieldModule, 40 | MatInputModule, 41 | MatListModule, 42 | MatDatepickerModule, 43 | MatNativeDateModule, 44 | MatMomentDateModule, 45 | MatSelectModule, 46 | MatOptionModule, 47 | MatCheckboxModule, 48 | MatRadioModule 49 | ] 50 | }) 51 | export class MaterialModule {} 52 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bahurudeen/dynamicform/9e362854d9e422d4e3c3060fbd04ed0156b2b4f9/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/browserslist: -------------------------------------------------------------------------------- 1 | # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | # For IE 9-11 support, please uncomment the last line of the file and adjust as needed 5 | > 0.5% 6 | last 2 versions 7 | Firefox ESR 8 | not dead 9 | # IE 9-11 -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build ---prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * In development mode, to ignore zone related error stack frames such as 11 | * `zone.run`, `zoneDelegate.invokeTask` for easier debugging, you can 12 | * import the following file, but please comment it out in production mode 13 | * because it will have performance impact when throw error 14 | */ 15 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 16 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bahurudeen/dynamicform/9e362854d9e422d4e3c3060fbd04ed0156b2b4f9/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | DynamicForm 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, '../coverage'), 20 | reports: ['html', 'lcovonly'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false 30 | }); 31 | }; -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.log(err)); 13 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/ 22 | // import 'core-js/es6/symbol'; 23 | // import 'core-js/es6/object'; 24 | // import 'core-js/es6/function'; 25 | // import 'core-js/es6/parse-int'; 26 | // import 'core-js/es6/parse-float'; 27 | // import 'core-js/es6/number'; 28 | // import 'core-js/es6/math'; 29 | // import 'core-js/es6/string'; 30 | // import 'core-js/es6/date'; 31 | // import 'core-js/es6/array'; 32 | // import 'core-js/es6/regexp'; 33 | // import 'core-js/es6/map'; 34 | // import 'core-js/es6/weak-map'; 35 | // import 'core-js/es6/set'; 36 | 37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 38 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 39 | 40 | /** IE10 and IE11 requires the following for the Reflect API. */ 41 | // import 'core-js/es6/reflect'; 42 | 43 | 44 | /** Evergreen browsers require these. **/ 45 | // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove. 46 | import 'core-js/es7/reflect'; 47 | 48 | 49 | /** 50 | * Web Animations `@angular/platform-browser/animations` 51 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 52 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 53 | **/ 54 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 55 | 56 | /** 57 | * By default, zone.js will patch all possible macroTask and DomEvents 58 | * user can disable parts of macroTask/DomEvents patch by setting following flags 59 | */ 60 | 61 | // (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 62 | // (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 63 | // (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 64 | 65 | /* 66 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 67 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 68 | */ 69 | // (window as any).__Zone_enable_cross_context_check = true; 70 | 71 | /*************************************************************************************************** 72 | * Zone JS is required by default for Angular itself. 73 | */ 74 | import 'zone.js/dist/zone'; // Included with Angular CLI. 75 | 76 | 77 | 78 | /*************************************************************************************************** 79 | * APPLICATION IMPORTS 80 | */ 81 | -------------------------------------------------------------------------------- /src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | 3 | body { 4 | margin: 0; 5 | } 6 | .demo-full-width { 7 | width: 100%; 8 | } 9 | .margin-top { 10 | margin-top: 15px; 11 | } 12 | .margin-left { 13 | margin-left: 10px; 14 | } 15 | .radio-label-padding { 16 | padding-right: 10px; 17 | color: grey; 18 | } 19 | .form { 20 | margin-left: 10px; 21 | border: 2px solid lightgray; 22 | width: 600px; 23 | padding-left: 5px; 24 | margin-top: 10px; 25 | } 26 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "es2015", 6 | "types": [] 7 | }, 8 | "exclude": [ 9 | "src/test.ts", 10 | "**/*.spec.ts" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "module": "commonjs", 6 | "types": [ 7 | "jasmine", 8 | "node" 9 | ] 10 | }, 11 | "files": [ 12 | "test.ts", 13 | "polyfills.ts" 14 | ], 15 | "include": [ 16 | "**/*.spec.ts", 17 | "**/*.d.ts" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tslint.json", 3 | "rules": { 4 | "directive-selector": [ 5 | true, 6 | "attribute", 7 | "app", 8 | "camelCase" 9 | ], 10 | "component-selector": [ 11 | true, 12 | "element", 13 | "app", 14 | "kebab-case" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "moduleResolution": "node", 9 | "emitDecoratorMetadata": true, 10 | "experimentalDecorators": true, 11 | "target": "es5", 12 | "typeRoots": [ 13 | "node_modules/@types" 14 | ], 15 | "lib": [ 16 | "es2017", 17 | "dom" 18 | ] 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "arrow-return-shorthand": true, 7 | "callable-types": true, 8 | "class-name": true, 9 | "comment-format": [ 10 | true, 11 | "check-space" 12 | ], 13 | "curly": true, 14 | "deprecation": { 15 | "severity": "warn" 16 | }, 17 | "eofline": true, 18 | "forin": true, 19 | "import-blacklist": [ 20 | true, 21 | "rxjs/Rx" 22 | ], 23 | "import-spacing": true, 24 | "indent": [ 25 | true, 26 | "spaces" 27 | ], 28 | "interface-over-type-literal": true, 29 | "label-position": true, 30 | "max-line-length": [ 31 | true, 32 | 140 33 | ], 34 | "member-access": false, 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-arg": true, 47 | "no-bitwise": true, 48 | "no-console": [ 49 | true, 50 | "debug", 51 | "info", 52 | "time", 53 | "timeEnd", 54 | "trace" 55 | ], 56 | "no-construct": true, 57 | "no-debugger": true, 58 | "no-duplicate-super": true, 59 | "no-empty": false, 60 | "no-empty-interface": true, 61 | "no-eval": true, 62 | "no-inferrable-types": [ 63 | true, 64 | "ignore-params" 65 | ], 66 | "no-misused-new": true, 67 | "no-non-null-assertion": true, 68 | "no-shadowed-variable": true, 69 | "no-string-literal": false, 70 | "no-string-throw": true, 71 | "no-switch-case-fall-through": true, 72 | "no-trailing-whitespace": true, 73 | "no-unnecessary-initializer": true, 74 | "no-unused-expression": true, 75 | "no-use-before-declare": true, 76 | "no-var-keyword": true, 77 | "object-literal-sort-keys": false, 78 | "one-line": [ 79 | true, 80 | "check-open-brace", 81 | "check-catch", 82 | "check-else", 83 | "check-whitespace" 84 | ], 85 | "prefer-const": true, 86 | "quotemark": [ 87 | true, 88 | "single" 89 | ], 90 | "radix": true, 91 | "semicolon": [ 92 | true, 93 | "always" 94 | ], 95 | "triple-equals": [ 96 | true, 97 | "allow-null-check" 98 | ], 99 | "typedef-whitespace": [ 100 | true, 101 | { 102 | "call-signature": "nospace", 103 | "index-signature": "nospace", 104 | "parameter": "nospace", 105 | "property-declaration": "nospace", 106 | "variable-declaration": "nospace" 107 | } 108 | ], 109 | "unified-signatures": true, 110 | "variable-name": false, 111 | "whitespace": [ 112 | true, 113 | "check-branch", 114 | "check-decl", 115 | "check-operator", 116 | "check-separator", 117 | "check-type" 118 | ], 119 | "no-output-on-prefix": true, 120 | "use-input-property-decorator": true, 121 | "use-output-property-decorator": true, 122 | "use-host-property-decorator": true, 123 | "no-input-rename": true, 124 | "no-output-rename": true, 125 | "use-life-cycle-interface": true, 126 | "use-pipe-transform-interface": true, 127 | "component-class-suffix": true, 128 | "directive-class-suffix": true 129 | } 130 | } 131 | --------------------------------------------------------------------------------