diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 66c870f..9285ba7 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,9 +2,15 @@
+
+
+
+
+
+
@@ -19,59 +25,27 @@
-
+
-
-
+
+
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -79,31 +53,10 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -112,28 +65,88 @@
-
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -157,22 +170,23 @@
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
-
@@ -222,7 +236,6 @@
-
@@ -408,6 +421,7 @@
+
@@ -533,7 +547,8 @@
-
+
+
1496129612668
@@ -563,11 +578,18 @@
1496756710062
-
+
+ 1496758683645
+
+
+
+ 1496758683645
+
+
-
+
@@ -580,12 +602,12 @@
+
-
+
-
@@ -599,6 +621,7 @@
+
@@ -648,6 +671,8 @@
+
+
@@ -659,7 +684,8 @@
-
+
+
@@ -668,24 +694,16 @@
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
@@ -704,13 +722,14 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
@@ -719,9 +738,7 @@
-
-
-
+
@@ -730,7 +747,8 @@
-
+
+
@@ -774,10 +792,10 @@
-
-
-
-
+
+
+
+
@@ -796,13 +814,14 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
@@ -811,9 +830,7 @@
-
-
-
+
@@ -832,7 +849,8 @@
-
+
+
@@ -853,14 +871,14 @@
+
+
+
-
-
-
@@ -889,35 +907,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -981,7 +970,6 @@
-
@@ -1008,53 +996,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1071,17 +1012,9 @@
-
-
-
-
-
-
-
-
-
+
@@ -1089,52 +1022,145 @@
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
+
-
-
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/app/modules/dyn-form/dyn-form.component.ts b/src/app/modules/dyn-form/dyn-form.component.ts
index c5d8c5c..bb1ad17 100644
--- a/src/app/modules/dyn-form/dyn-form.component.ts
+++ b/src/app/modules/dyn-form/dyn-form.component.ts
@@ -45,7 +45,7 @@ export class DynFormComponent implements OnChanges {
let vals = {};
let type: string = this.form.value.type;
for (let question of this.questions) {
- let specType = question.properties.spezialization;
+ let specType = question.properties.specialization;
let methods = question.properties.methods;
let key = question.properties.key;
if (!(methods && methods.indexOf(this.type)==-1 || specType && type!=specType)) {
diff --git a/src/app/modules/dyn-form/dyn-form.module.ts b/src/app/modules/dyn-form/dyn-form.module.ts
index b8a928c..67fd140 100644
--- a/src/app/modules/dyn-form/dyn-form.module.ts
+++ b/src/app/modules/dyn-form/dyn-form.module.ts
@@ -12,6 +12,7 @@ import {TextareaInputComponent} from './inputs/textarea-input.component';
import {ValueService} from './services/value.service';
import {KeysPipe} from './types/keys.pipe';
import {TextboxInputComponent} from './inputs/textbox-input.component';
+import {CheckboxInputComponent} from './inputs/checkbox-input.component';
@NgModule({
@@ -31,6 +32,7 @@ import {TextboxInputComponent} from './inputs/textbox-input.component';
DropdownInputComponent,
TextareaInputComponent,
TextboxInputComponent,
+ CheckboxInputComponent,
KeysPipe
],
providers: [
diff --git a/src/app/modules/dyn-form/dyn-question.component.ts b/src/app/modules/dyn-form/dyn-question.component.ts
index 03f5b70..fe648aa 100644
--- a/src/app/modules/dyn-form/dyn-question.component.ts
+++ b/src/app/modules/dyn-form/dyn-question.component.ts
@@ -34,6 +34,10 @@ import {FormGroup, ValidationErrors} from '@angular/forms';
[type]="question.properties.type" [constraints]="question.constraints"
[placeholder]="question.properties.placeholder"
(ngModelChange)="change()">
+
- {{error}}
@@ -57,6 +61,7 @@ export class DynQuestionComponent {
setTimeout(() => {
this.errorList = [];
let control = this.form.controls[this.question.properties.key];
+ console.log("XX", this.question.properties.key, control.untouched, control.valid);
if (control.untouched || control.valid)
return null;
let errors: ValidationErrors = control.errors;
diff --git a/src/app/modules/dyn-form/inputs/checkbox-input.component.ts b/src/app/modules/dyn-form/inputs/checkbox-input.component.ts
new file mode 100644
index 0000000..8767273
--- /dev/null
+++ b/src/app/modules/dyn-form/inputs/checkbox-input.component.ts
@@ -0,0 +1,60 @@
+import {Component, forwardRef, Input} from '@angular/core';
+import { NG_VALUE_ACCESSOR, NG_VALIDATORS, FormControl, ValidationErrors } from '@angular/forms';
+import {CustomInputComponent} from "./custom-input.component";
+
+@Component({
+ selector: 'checkbox-input',
+ template:
+ `
+
+
+
+ {{value ? "Yes" : (value===false ? "No" : "N/A")}}
+ `,
+ providers: [
+ {
+ provide: NG_VALUE_ACCESSOR,
+ useExisting: forwardRef(() => CheckboxInputComponent),
+ multi: true,
+ },
+ {
+ provide: NG_VALIDATORS,
+ useExisting: forwardRef(() => CheckboxInputComponent),
+ multi: true,
+ }]
+})
+export class CheckboxInputComponent extends CustomInputComponent {
+ @Input() readonly: boolean = false;
+ @Input() nullable: boolean = false;
+
+
+ // set initial value
+ public writeValue(obj: any): void {
+ if (obj) {
+ this.value = true;
+ } else if (obj===false) {
+ this.value = false;
+ } else {
+ this.value = null;
+ }
+ if (this.value !== obj)
+ setTimeout(() => super.change(true), 0);
+ }
+
+ // validates the form, returns null when valid else the validation object
+ public validate(c: FormControl): ValidationErrors {
+ if (!this.initComplete)
+ return null;
+ return this.nullable || (this.value) || (this.value===false) ? null : {notNullable: {
+ valid: false,
+ message: "This field is required!"
+ }};
+ }
+
+ // on button click
+ protected onChange(newValue: boolean): void {
+ this.value = newValue;
+
+ super.change();
+ }
+}
\ No newline at end of file
diff --git a/src/app/modules/dyn-form/inputs/custom-input.component.ts b/src/app/modules/dyn-form/inputs/custom-input.component.ts
index 85a2b74..9f3d008 100644
--- a/src/app/modules/dyn-form/inputs/custom-input.component.ts
+++ b/src/app/modules/dyn-form/inputs/custom-input.component.ts
@@ -8,6 +8,7 @@ export abstract class CustomInputComponent implements ControlValueAccessor, Vali
private propagateTouch: () => void = () => {};
protected initComplete: boolean = false;
private isTouched: boolean = false;
+ private initialChangeDone = false;
public ngAfterViewInit() {
setTimeout(() => {
@@ -34,9 +35,11 @@ export abstract class CustomInputComponent implements ControlValueAccessor, Vali
// on change
protected change(noTouch?: boolean): void {
- if (!noTouch)
+ if (!noTouch && this.initialChangeDone) {
this.touch();
+ }
this.propagateChange(this.value);
+ this.initialChangeDone = true;
}
// on change
diff --git a/src/app/modules/dyn-form/inputs/tag-input.component.ts b/src/app/modules/dyn-form/inputs/tag-input.component.ts
index ee46d32..175d01a 100644
--- a/src/app/modules/dyn-form/inputs/tag-input.component.ts
+++ b/src/app/modules/dyn-form/inputs/tag-input.component.ts
@@ -50,7 +50,7 @@ export class TagInputComponent extends CustomInputComponent {
console.log("writeValue", isUpdated, this.value);
if (isUpdated) {
- setTimeout(() => super.change(true), 0);
+ setTimeout(() => this.change(true), 0);
}
}
@@ -75,7 +75,7 @@ export class TagInputComponent extends CustomInputComponent {
this.value = Object.assign({}, this.value);
this.value[key] = value;
- super.change();
+ this.change();
return false;
}
}
\ No newline at end of file
diff --git a/src/app/modules/dyn-form/services/question.service.ts b/src/app/modules/dyn-form/services/question.service.ts
index 8013126..8f91a0e 100644
--- a/src/app/modules/dyn-form/services/question.service.ts
+++ b/src/app/modules/dyn-form/services/question.service.ts
@@ -52,7 +52,18 @@ export class QuestionService {
key: 'textarea',
label: 'Textareaaaa',
order: 4,
- spezialization: 'world'
+ specialization: 'world',
+ methods: ['insert']
+ }, constraints: {
+ optional: false
+ }
+ }, {
+ type: 'checkbox',
+ description: 'This is a very long box. Fill it!',
+ properties: {
+ key: 'checki',
+ label: 'To be or not to be?',
+ order: 5
}, constraints: {
optional: false
}
diff --git a/src/app/modules/dyn-form/types/question.interface.ts b/src/app/modules/dyn-form/types/question.interface.ts
index fdb1bb8..3543980 100644
--- a/src/app/modules/dyn-form/types/question.interface.ts
+++ b/src/app/modules/dyn-form/types/question.interface.ts
@@ -1,5 +1,5 @@
export interface QuestionInterface {
- type: "flag"|"textbox"|"textarea"|"hidden"|"dropdown",
+ type: "flag"|"textbox"|"textarea"|"hidden"|"dropdown"|"checkbox",
description: string,
properties: {
key: string,
@@ -7,7 +7,7 @@ export interface QuestionInterface {
order: number,
methods?: Array,
- spezialization?: string,
+ specialization?: string,
// textbox
type?: string,