|
@@ -1,7 +1,3 @@
|
|
|
-import { FormBuilder, FormGroup, FormControl } from '@angular/forms';
|
|
|
-import { reduce } from 'lodash/fp';
|
|
|
-import * as fmdModels from './../models';
|
|
|
-
|
|
|
/*
|
|
|
* FORM METADATA UTILITIES
|
|
|
*
|
|
@@ -21,6 +17,19 @@ import * as fmdModels from './../models';
|
|
|
*
|
|
|
*/
|
|
|
|
|
|
+import { FormBuilder, FormGroup, FormControl, ValidatorFn, AsyncValidatorFn } from '@angular/forms';
|
|
|
+import { reduce } from 'lodash/fp';
|
|
|
+import * as fmdModels from './../models';
|
|
|
+
|
|
|
+// REMINDER: Import this directly from @angular/forms when we upgrade to Angular 6
|
|
|
+// While we're still' on Angular 5 just declare it
|
|
|
+interface AbstractControlOptions {
|
|
|
+ validators?: ValidatorFn | ValidatorFn[] | null
|
|
|
+ asyncValidators?: AsyncValidatorFn | AsyncValidatorFn[] | null
|
|
|
+ updateOn?: 'change' | 'blur' | 'submit'
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
|
// Raw Model (or Mapped Raw Model) to Automatic Metadata
|
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
@@ -106,12 +115,12 @@ const buildFormGroupFunctionFactory = (fb: FormBuilder): (meta) => FormGroup =>
|
|
|
// Build Form Control
|
|
|
// TODO: Flesh out function to build validators
|
|
|
const buildControlState = metaF => ({ value: metaF.value || metaF.default, disabled: metaF.isDisabled });
|
|
|
- const buildValidators = metaF => ({
|
|
|
- validators: null,
|
|
|
- asyncValidators: null,
|
|
|
+ const buildValidators = (metaF): AbstractControlOptions => ({
|
|
|
+ validators: metaF.validators,
|
|
|
+ asyncValidators: metaF.asyncValidators,
|
|
|
updateOn: 'blur'
|
|
|
});
|
|
|
- const buildFormControl = metaF => new FormControl(buildControlState(metaF) /*, buildValidators(metaF) */);
|
|
|
+ const buildFormControl = metaF => new FormControl(buildControlState(metaF), buildValidators(metaF));
|
|
|
|
|
|
// Build Form Group Member
|
|
|
const buildFormGroupMember = metaFoG => isGroup(metaFoG) ?
|
|
@@ -130,7 +139,7 @@ const buildFormGroupFunctionFactory = (fb: FormBuilder): (meta) => FormGroup =>
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
|
-// Helper Funstions
|
|
|
+// Helper Functions
|
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
// Add Property to object
|