|
@@ -26,6 +26,7 @@
|
|
|
import { FormBuilder, FormGroup, FormArray, FormControl, AbstractControl, AbstractControlOptions } from '@angular/forms';
|
|
|
import { cloneDeep, omit, reduce } from 'lodash/fp';
|
|
|
import * as fmdModels from '../models/field.model';
|
|
|
+import { meta } from '@mock/testfields.v1';
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
@@ -47,7 +48,7 @@ const keyValPairToMetaRecursive = ( [key, val] ) => {
|
|
|
|
|
|
const arrayToMeta = array => array.map((val, i) => {
|
|
|
if (isScalar(val)) {
|
|
|
- return { name: `item${i + 1}`, 'value' : val };
|
|
|
+ return { name: `item${i + 1}`, value : val, label: val };
|
|
|
} else {
|
|
|
return { name: `group${i + 1}`, meta: autoMeta(val) };
|
|
|
}
|
|
@@ -721,7 +722,7 @@ const isRepeating = (metaFoG): boolean => !!(metaFoG.minRepeat || metaFoG.maxRep
|
|
|
|
|
|
// Is Repeating Field
|
|
|
// Helper function to distinguish a repeating field (a field that can be repeated 1...N times)
|
|
|
-const isRepeatingField = (metaRF): boolean => metaRF.type && metaRF.type.toLowerCase() === 'repeatingfield'
|
|
|
+const isRepeatingField = (metaRF): boolean => typeof metaRF.type === 'string' && metaRF.type.toLowerCase() === 'repeatingfield'
|
|
|
|| (
|
|
|
!metaRF.type
|
|
|
&& isRepeating(metaRF)
|
|
@@ -735,7 +736,7 @@ const isRepeatingField = (metaRF): boolean => metaRF.type && metaRF.type.toLower
|
|
|
|
|
|
// Is Container
|
|
|
// Helper function to distinguish container group (a group of child fields)
|
|
|
-const isContainer = (metaFoG): boolean => metaFoG.type && metaFoG.type.toLowerCase() === 'container'
|
|
|
+const isContainer = (metaFoG): boolean => typeof metaFoG.type === 'string' && metaFoG.type.toLowerCase() === 'container'
|
|
|
|| (
|
|
|
!metaFoG.type
|
|
|
&& hasMeta(metaFoG)
|
|
@@ -744,7 +745,7 @@ const isContainer = (metaFoG): boolean => metaFoG.type && metaFoG.type.toLowerCa
|
|
|
|
|
|
// Is Repeating Container
|
|
|
// Helper function to distinguish a repeating container group (a group of child fields that can be repeated 1...N times)
|
|
|
-const isRepeatingContainer = (metaFoG): boolean => metaFoG.type && metaFoG.type.toLowerCase() === 'repeatingcontainer'
|
|
|
+const isRepeatingContainer = (metaFoG): boolean => typeof metaFoG.type === 'string' && metaFoG.type.toLowerCase() === 'repeatingcontainer'
|
|
|
|| (
|
|
|
!metaFoG.type
|
|
|
&& isRepeating(metaFoG)
|
|
@@ -761,7 +762,11 @@ const addNameIfMissing = (metaFoG, key) => metaFoG.name ? metaFoG : addProp(meta
|
|
|
const addNameToSelfAndChildren = ( [key, metaFoG] ) => {
|
|
|
metaFoG = addNameIfMissing(metaFoG, key);
|
|
|
if (hasMeta(metaFoG) && !isRepeatingContainer(metaFoG)) {
|
|
|
- metaFoG.meta = isArray(metaFoG.meta) ? Object.values(addMissingNames(metaFoG.meta)) : addMissingNames(metaFoG.meta); // Recursion
|
|
|
+ if (metaFoG.meta.length && metaFoG.meta.every(isScalar)) {
|
|
|
+ metaFoG.meta = metaFoG.meta.map(val => ({ name: val, value: val }));
|
|
|
+ } else {
|
|
|
+ metaFoG.meta = isArray(metaFoG.meta) ? Object.values(addMissingNames(metaFoG.meta)) : addMissingNames(metaFoG.meta); // Recursion
|
|
|
+ }
|
|
|
}
|
|
|
return [key, metaFoG];
|
|
|
};
|