@@ -22,7 +22,7 @@ const model = {
const meta = {
dynaformtest: {
meta: {
- a: { validators: Validators.required },
+ a: { validators: [ Validators.required, Validators.minLength(4) ] },
b: { type: 'checkbutton' },
c: { label: 'Property Three', type: 'radio', options: ['Yes', 'No', 'Maybe'], horizontal: 1 },
d: {
@@ -17,7 +17,8 @@
</form>
<div calss="row">
<div class="col-12 pt-4 pb-4">
- <json-formatter [data]="form.value" open="4"></json-formatter>
+ <!-- <json-formatter [data]="form.value" open="4"></json-formatter> -->
+ <json-formatter [data]="form.errors" open="4"></json-formatter>
</div>
@@ -1,4 +1,4 @@
-import { Component, OnInit, ViewChild, TemplateRef } from '@angular/core';
+import { Component, OnInit, OnChanges, ViewChild, TemplateRef } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { DynaformService } from './dynaform/services/dynaform.service';
@@ -9,7 +9,7 @@ import { model, meta as lazyMeta } from './_mock/testfields.v6';
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
-export class AppComponent implements OnInit {
+export class AppComponent implements OnInit, OnChanges {
form: FormGroup;
meta: StringMap;
@@ -27,5 +27,9 @@ export class AppComponent implements OnInit {
console.dir(this.form);
console.dir(this.meta);
}
+
+ ngOnChanges() {
+ console.log(this.form.errors);
+ }
@@ -147,11 +147,11 @@ const addProp = (obj, key, val) => { obj[key] = val; return obj; };
// Is Group
// Helper function to distinguish group from field
-const isGroup = metaFoG => metaFoG.meta;
+const isGroup = (metaFoG): boolean => !!metaFoG.meta;
// Is Container
// Helper function to distinguish container group (a group of child fields)
-const isContainer = metaFoG => isGroup(metaFoG) && (metaFoG.type === 'container' || typeof metaFoG.type === 'undefined');
+const isContainer = (metaFoG): boolean => isGroup(metaFoG) && (metaFoG.type === 'container' || typeof metaFoG.type === 'undefined');
// Add Missing Names
// Helper function to add any missing 'name' properties to Fields and Groups using property's key, recursively