|
@@ -140,12 +140,14 @@ const combineExtraMeta = (metaG, extraMeta, createFromExtra = false, containerSe
|
|
// We've got a repeating field
|
|
// We've got a repeating field
|
|
const metaForFieldToRepeat = {
|
|
const metaForFieldToRepeat = {
|
|
...containerSeed,
|
|
...containerSeed,
|
|
- ...omit(['seed', 'minRepeat', 'maxRepeat', 'initialRepeat', 'showAddControl', 'showDeleteControl'], val as StringMap<any>)
|
|
|
|
|
|
+ ...omit(['seed', 'minRepeat', 'maxRepeat', 'initialRepeat', 'showAddControl', 'showDeleteControl'], val as StringMap<any>),
|
|
|
|
+ label: `${val.label || key}`
|
|
};
|
|
};
|
|
delete val.type;
|
|
delete val.type;
|
|
extra = {
|
|
extra = {
|
|
...val,
|
|
...val,
|
|
- meta: Array.from(Array(val.initialRepeat || 1).keys()).map((f, i) => ({ ...metaForFieldToRepeat, label: `${val.label || key} ${i + 1}` }))
|
|
|
|
|
|
+ meta: Array.from(Array(val.initialRepeat || 1).keys()).map((f, i) => metaForFieldToRepeat),
|
|
|
|
+ __fieldTemplate: metaForFieldToRepeat
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
// We've got a standard field
|
|
// We've got a standard field
|
|
@@ -238,16 +240,16 @@ const buildFieldSpecificMetaInClosure = (metaG, context) => {
|
|
// Build Form Group Member
|
|
// Build Form Group Member
|
|
const buildModeledFieldGroupMember = (metaFoG) => {
|
|
const buildModeledFieldGroupMember = (metaFoG) => {
|
|
const modeledGroupMember = buildModeledField(metaFoG);
|
|
const modeledGroupMember = buildModeledField(metaFoG);
|
|
-
|
|
|
|
- console.log('------------- DEBUGGING -------------');
|
|
|
|
|
|
+ /*
|
|
|
|
+ console.log('------------- DEBUGGING --->', metaFoG.name);
|
|
console.log(modeledGroupMember);
|
|
console.log(modeledGroupMember);
|
|
console.log('IS REP Field', isRepeatingField(modeledGroupMember));
|
|
console.log('IS REP Field', isRepeatingField(modeledGroupMember));
|
|
console.log('IS REP Container', isRepeatingContainer(modeledGroupMember));
|
|
console.log('IS REP Container', isRepeatingContainer(modeledGroupMember));
|
|
console.log('IS ORD Container', isContainer(modeledGroupMember));
|
|
console.log('IS ORD Container', isContainer(modeledGroupMember));
|
|
- console.log(modeledGroupMember);
|
|
|
|
-
|
|
|
|
|
|
+ */
|
|
if (isRepeatingField(modeledGroupMember)) {
|
|
if (isRepeatingField(modeledGroupMember)) {
|
|
modeledGroupMember.meta = modeledGroupMember.meta.map(metaF => buildModeledField(metaF));
|
|
modeledGroupMember.meta = modeledGroupMember.meta.map(metaF => buildModeledField(metaF));
|
|
|
|
+ modeledGroupMember.__fieldTemplate = buildModeledField(modeledGroupMember.__fieldTemplate);
|
|
} else if (isContainer(modeledGroupMember)) {
|
|
} else if (isContainer(modeledGroupMember)) {
|
|
modeledGroupMember.meta = _buildFieldSpecificMeta(modeledGroupMember.meta);
|
|
modeledGroupMember.meta = _buildFieldSpecificMeta(modeledGroupMember.meta);
|
|
} else if (isRepeatingContainer(modeledGroupMember)) {
|
|
} else if (isRepeatingContainer(modeledGroupMember)) {
|
|
@@ -269,9 +271,6 @@ const buildFieldSpecificMetaInClosure = (metaG, context) => {
|
|
reduce(buildModeledFieldGroupReducerIteree, {}, metaG);
|
|
reduce(buildModeledFieldGroupReducerIteree, {}, metaG);
|
|
const buildFieldSpecificMeta = metaG => _buildFieldSpecificMeta(addMissingNames(metaG));
|
|
const buildFieldSpecificMeta = metaG => _buildFieldSpecificMeta(addMissingNames(metaG));
|
|
|
|
|
|
- // DEBUGGING
|
|
|
|
- console.log('buildFieldSpecificMetaInClosure', metaG, context);
|
|
|
|
-
|
|
|
|
return buildFieldSpecificMeta(metaG); // RUN CODE
|
|
return buildFieldSpecificMeta(metaG); // RUN CODE
|
|
}
|
|
}
|
|
|
|
|
|
@@ -409,18 +408,21 @@ const extractFieldMappings = (metaG, parentPath = '') => Object.entries(metaG)
|
|
// TODO: In progress: elegantly adding validators at FormGroup and FormArray levels
|
|
// TODO: In progress: elegantly adding validators at FormGroup and FormArray levels
|
|
// Working, but code needs a rework
|
|
// Working, but code needs a rework
|
|
|
|
|
|
|
|
+// Build Form Control
|
|
|
|
+const buildControlState = metaF => ({ value: metaF.value || metaF.default, disabled: metaF.disabled });
|
|
|
|
+const buildValidators = (metaFoG): AbstractControlOptions => ({
|
|
|
|
+ validators: metaFoG.validators,
|
|
|
|
+ asyncValidators: metaFoG.asyncValidators,
|
|
|
|
+ // blur not working for custom components, so use change for custom and blur for text
|
|
|
|
+ updateOn: getUpdateOn(metaFoG.type)
|
|
|
|
+});
|
|
|
|
+const buildFormControl = metaF => new FormControl(buildControlState(metaF), buildValidators(metaF));
|
|
|
|
+
|
|
|
|
+// Build Form Group - uses the 3 functions avove
|
|
const buildFormGroupFunctionFactory = (fb: FormBuilder): (meta) => FormGroup => {
|
|
const buildFormGroupFunctionFactory = (fb: FormBuilder): (meta) => FormGroup => {
|
|
// Establishes a closure over the supplied FormBuilder and returns a function that builds FormGroups from metadata
|
|
// Establishes a closure over the supplied FormBuilder and returns a function that builds FormGroups from metadata
|
|
// ( it's done this way so we can use the FormBuilder singleton without reinitialising )
|
|
// ( it's done this way so we can use the FormBuilder singleton without reinitialising )
|
|
|
|
|
|
- // Build Form Control
|
|
|
|
- const buildControlState = metaF => ({ value: metaF.value || metaF.default, disabled: metaF.disabled });
|
|
|
|
- const buildValidators = (metaFoG): AbstractControlOptions => ({
|
|
|
|
- validators: metaFoG.validators,
|
|
|
|
- asyncValidators: metaFoG.asyncValidators,
|
|
|
|
- // blur not working for custom components, so use change for custom and blur for text
|
|
|
|
- updateOn: getUpdateOn(metaFoG.type)
|
|
|
|
- });
|
|
|
|
const BVAL = metaFoG => {
|
|
const BVAL = metaFoG => {
|
|
if (!metaFoG || !(metaFoG.validators || metaFoG.asyncValidators)) {
|
|
if (!metaFoG || !(metaFoG.validators || metaFoG.asyncValidators)) {
|
|
return undefined;
|
|
return undefined;
|
|
@@ -430,7 +432,6 @@ const buildFormGroupFunctionFactory = (fb: FormBuilder): (meta) => FormGroup =>
|
|
console.log(res);
|
|
console.log(res);
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
- const buildFormControl = metaF => new FormControl(buildControlState(metaF), buildValidators(metaF));
|
|
|
|
|
|
|
|
// Build Form Array containing either Form Controls or Form Groups
|
|
// Build Form Array containing either Form Controls or Form Groups
|
|
const buildFormArray = (metaG, grMeta?): FormArray => {
|
|
const buildFormArray = (metaG, grMeta?): FormArray => {
|
|
@@ -751,7 +752,8 @@ const isRepeatingContainer = (metaFoG): boolean => metaFoG.type && metaFoG.type.
|
|
!metaFoG.type
|
|
!metaFoG.type
|
|
&& isRepeating(metaFoG)
|
|
&& isRepeating(metaFoG)
|
|
&& hasMeta(metaFoG)
|
|
&& hasMeta(metaFoG)
|
|
- && Array.isArray(metaFoG.meta) && metaFoG.meta[0]
|
|
|
|
|
|
+ && Array.isArray(metaFoG.meta)
|
|
|
|
+ && metaFoG.meta[0]
|
|
&& !isScalar(Object.values(metaFoG.meta[0])[0])
|
|
&& !isScalar(Object.values(metaFoG.meta[0])[0])
|
|
);
|
|
);
|
|
|
|
|
|
@@ -791,6 +793,7 @@ const addMissingFieldSpecificMeta = metaG => Object.entries(metaG)
|
|
export {
|
|
export {
|
|
autoMeta, combineModelWithMeta, combineExtraMeta, execMetaReorderingInstructions,
|
|
autoMeta, combineModelWithMeta, combineExtraMeta, execMetaReorderingInstructions,
|
|
buildFieldSpecificMetaInClosure, extractFieldMappings,
|
|
buildFieldSpecificMetaInClosure, extractFieldMappings,
|
|
|
|
+ buildFormControl,
|
|
buildFormGroupFunctionFactory,
|
|
buildFormGroupFunctionFactory,
|
|
resetAsyncValidatorsRecursive,
|
|
resetAsyncValidatorsRecursive,
|
|
touchAndUpdateValidityRecursive, resetValidityRecursive,
|
|
touchAndUpdateValidityRecursive, resetValidityRecursive,
|