|
@@ -33,8 +33,8 @@ const addProp = (obj, key, val) => { obj[key] = val; return obj; };
|
|
|
const isGroup = metaFoG => metaFoG.meta;
|
|
|
|
|
|
// Is Container
|
|
|
-// Helper function to distinguish container group
|
|
|
-const isContainer = metaFoG => metaFoG.type === 'container';
|
|
|
+// Helper function to distinguish container group (a group of child fields)
|
|
|
+const isContainer = metaFoG => isGroup(metaFoG) && (metaFoG.type === 'container' || typeof metaFoG.type === 'undefined');
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
|
// Add Missing Names
|
|
@@ -77,7 +77,7 @@ const combineExtraMeta = (metaG, metaExtra) => {
|
|
|
Object.entries(metaExtra).forEach(([key, val]) => {
|
|
|
if (typeof metaG[key] === 'object') {
|
|
|
combinedMeta[key] = (<any>val).meta ?
|
|
|
- combineExtraMeta(metaG[key].meta, (<any>val).meta) :
|
|
|
+ combineMetaForField(metaG[key], { meta: combineExtraMeta(metaG[key].meta, (<any>val).meta) }) :
|
|
|
combineMetaForField(metaG[key], val);
|
|
|
}
|
|
|
});
|
|
@@ -95,14 +95,13 @@ const buildClassName = (t = 'text') => {
|
|
|
return start + 'Field';
|
|
|
};
|
|
|
|
|
|
-const buildModeledField = metaF => {
|
|
|
- // TODO: Add validity check
|
|
|
- const fieldType = buildClassName(metaF.type);
|
|
|
+const buildModeledField = metaFoG => {
|
|
|
+ const type = isContainer(metaFoG) ? 'container' : metaFoG.type;
|
|
|
+ const fieldType = buildClassName(type);
|
|
|
if (!fmdModels[fieldType]) {
|
|
|
- throw new Error('Unknown Field Type');
|
|
|
+ throw new Error(`No model for field type "${type}"`);
|
|
|
}
|
|
|
- const modeledMetaF = new fmdModels[fieldType](metaF);
|
|
|
- return modeledMetaF;
|
|
|
+ return new fmdModels[fieldType](metaFoG);
|
|
|
};
|
|
|
|
|
|
// Build Form Group Member
|