aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/components/genericForm/generic-form.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'vid-webpack-master/src/app/shared/components/genericForm/generic-form.component.ts')
-rw-r--r--vid-webpack-master/src/app/shared/components/genericForm/generic-form.component.ts45
1 files changed, 45 insertions, 0 deletions
diff --git a/vid-webpack-master/src/app/shared/components/genericForm/generic-form.component.ts b/vid-webpack-master/src/app/shared/components/genericForm/generic-form.component.ts
new file mode 100644
index 000000000..6febd66d6
--- /dev/null
+++ b/vid-webpack-master/src/app/shared/components/genericForm/generic-form.component.ts
@@ -0,0 +1,45 @@
+import {Component, EventEmitter, Input, OnChanges, Output, SimpleChanges} from '@angular/core';
+import {GenericFormService} from "./generic-form.service";
+import {FormControlModel} from "../../models/formControlModels/formControl.model";
+import {FormGroup} from "@angular/forms";
+import * as _ from 'lodash';
+
+@Component({
+ selector : 'generic-form',
+ templateUrl : './generic-form.component.html',
+ styleUrls : ['./generic-form.component.scss']
+})
+
+export class GenericFormComponent implements OnChanges{
+ genericFormService: GenericFormService = null;
+ dynamicFormGroup: FormGroup = null;
+
+ @Input() formControls : FormControlModel[] = null;
+ @Input() dynamicInputs : FormControlModel[] = null;
+ @Input() isValidForm : boolean = false;
+ @Output() onFormChanged = new EventEmitter();
+
+ constructor(private _genericFormService: GenericFormService){
+ this.genericFormService = _genericFormService;
+ }
+
+ ngOnChanges(changes: SimpleChanges): void {
+ if (changes["formControls"] !== undefined && changes["formControls"].currentValue !== changes["formControls"].previousValue) {
+ this.dynamicFormGroup = this._genericFormService.generateFormBuilder(this.formControls, this.dynamicInputs);
+ this.onFormChanged.next(this.dynamicFormGroup);
+ this.dynamicFormGroup.valueChanges.subscribe(() => {
+ this.onFormChanged.next(this.dynamicFormGroup);
+ })
+ }
+ }
+
+ hasApiError(controlName: string, data: any[], form: FormGroup) {
+ if (!_.isNil(data)) {
+ if (!form.controls[controlName].disabled && data.length === 0) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
+