Skip to content

Commit b1f291a

Browse files
committed
FIO-10408: Fixed issues with the nested field validations.
1 parent 4c826bc commit b1f291a

4 files changed

Lines changed: 52 additions & 48 deletions

File tree

src/process/process.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ export async function process<ProcessScope>(
3434
components,
3535
data,
3636
async (component, compData, row, path, components, index, parent) => {
37-
// Skip processing if row is null or undefined
38-
if (!row) {
39-
return;
40-
}
4137
await processOne<ProcessScope>({
4238
...context,
4339
data: compData,
@@ -74,10 +70,6 @@ export function processSync<ProcessScope>(context: ProcessContext<ProcessScope>)
7470
components,
7571
data,
7672
(component, compData, row, path, components, index, parent) => {
77-
// Skip processing if row is null or undefined
78-
if (!row) {
79-
return;
80-
}
8173
processOneSync<ProcessScope>({
8274
...context,
8375
data: compData,

src/process/processOne.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ export async function processOne<ProcessorScope>(context: ProcessorsContext<Proc
3333
// If the component has ephemeral state, then we need to reset it in case this is e.g. a data grid,
3434
// in which each row needs to be validated independently
3535
resetEphermalState(component);
36-
37-
if (!context.row) {
38-
return;
39-
}
4036
context.processor = ProcessorType.Custom;
4137
for (const processor of processors) {
4238
if (processor?.process) {
@@ -69,10 +65,6 @@ export function processOneSync<ProcessorScope>(context: ProcessorsContext<Proces
6965

7066
// If the component has ephemeral state, then we need to reset the ephemeral state in case this is e.g. a data grid, in which each row needs to be validated independently
7167
resetEphermalState(component);
72-
73-
if (!context.row) {
74-
return;
75-
}
7668
context.processor = ProcessorType.Custom;
7769
for (const processor of processors) {
7870
if (processor?.processSync) {

src/utils/formUtil/eachComponentData.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,40 @@ export const eachComponentData = (
3737
if (fn(component, data, row, compPath, componentComponents, index, compParent) === true) {
3838
return true;
3939
}
40+
const modelType = getModelType(component);
4041
if (isComponentNestedDataType(component)) {
41-
const value = get(data, compPath, data) as DataObject;
42-
if (Array.isArray(value)) {
43-
for (let i = 0; i < value.length; i++) {
44-
const nestedComponentPath =
45-
getModelType(component) === 'nestedDataArray'
46-
? `${compPath}[${i}].data`
47-
: `${compPath}[${i}]`;
42+
const value = get(data, compPath) as DataObject;
43+
if (modelType === 'nestedArray' || modelType === 'nestedDataArray') {
44+
if (Array.isArray(value) && value.length) {
45+
for (let i = 0; i < value.length; i++) {
46+
const nestedComponentPath =
47+
modelType === 'nestedDataArray' ? `${compPath}[${i}].data` : `${compPath}[${i}]`;
48+
eachComponentData(
49+
component.components,
50+
data,
51+
fn,
52+
nestedComponentPath,
53+
i,
54+
component,
55+
includeAll,
56+
);
57+
}
58+
return true;
59+
} else if (includeAll) {
4860
eachComponentData(
4961
component.components,
5062
data,
5163
fn,
52-
nestedComponentPath,
53-
i,
64+
modelType === 'nestedDataArray' ? `${compPath}[0].data` : `${compPath}[0]`,
65+
0,
5466
component,
5567
includeAll,
5668
);
69+
} else {
70+
// This is an empty nested array, so we do not need to process the children.
71+
return true;
5772
}
58-
return true;
59-
} else if (isEmpty(row) && !includeAll) {
60-
// Tree components may submit empty objects; since we've already evaluated the parent tree/layout component, we won't worry about constituent elements
61-
return true;
62-
}
63-
if (getModelType(component) === 'dataObject') {
73+
} else if (modelType === 'dataObject') {
6474
const nestedFormValue: any = get(data, component.path);
6575
const noReferenceAttached = nestedFormValue?._id
6676
? isEmpty(nestedFormValue.data) && !has(nestedFormValue, 'form')
@@ -97,7 +107,7 @@ export const eachComponentData = (
97107
);
98108
}
99109
return true;
100-
} else if (getModelType(component) === 'none') {
110+
} else if (modelType === 'none') {
101111
const info = componentInfo(component);
102112
if (info.hasColumns) {
103113
const columnsComponent = component as HasColumns;

src/utils/formUtil/eachComponentDataAsync.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,30 +40,40 @@ export const eachComponentDataAsync = async (
4040
) {
4141
return true;
4242
}
43+
const modelType = getModelType(component);
4344
if (isComponentNestedDataType(component)) {
44-
const value = get(data, compPath, data);
45-
if (Array.isArray(value)) {
46-
for (let i = 0; i < value.length; i++) {
47-
const nestedComponentPath =
48-
getModelType(component) === 'nestedDataArray'
49-
? `${compPath}[${i}].data`
50-
: `${compPath}[${i}]`;
45+
const value = get(data, compPath);
46+
if (modelType === 'nestedArray' || modelType === 'nestedDataArray') {
47+
if (Array.isArray(value) && value.length) {
48+
for (let i = 0; i < value.length; i++) {
49+
const nestedComponentPath =
50+
modelType === 'nestedDataArray' ? `${compPath}[${i}].data` : `${compPath}[${i}]`;
51+
await eachComponentDataAsync(
52+
component.components,
53+
data,
54+
fn,
55+
nestedComponentPath,
56+
i,
57+
component,
58+
includeAll,
59+
);
60+
}
61+
return true;
62+
} else if (includeAll) {
5163
await eachComponentDataAsync(
5264
component.components,
5365
data,
5466
fn,
55-
nestedComponentPath,
56-
i,
67+
modelType === 'nestedDataArray' ? `${compPath}[0].data` : `${compPath}[0]`,
68+
0,
5769
component,
5870
includeAll,
5971
);
72+
} else {
73+
// This is an empty nested array, so we do not need to process the children.
74+
return true;
6075
}
61-
return true;
62-
} else if (isEmpty(row) && !includeAll) {
63-
// Tree components may submit empty objects; since we've already evaluated the parent tree/layout component, we won't worry about constituent elements
64-
return true;
65-
}
66-
if (getModelType(component) === 'dataObject') {
76+
} else if (modelType === 'dataObject') {
6777
const nestedFormValue: any = get(data, component.path);
6878
const noReferenceAttached = nestedFormValue?._id
6979
? isEmpty(nestedFormValue.data) && !has(nestedFormValue, 'form')
@@ -100,7 +110,7 @@ export const eachComponentDataAsync = async (
100110
);
101111
}
102112
return true;
103-
} else if (getModelType(component) === 'none') {
113+
} else if (modelType === 'none') {
104114
const info = componentInfo(component);
105115
if (info.hasColumns) {
106116
const columnsComponent = component as HasColumns;

0 commit comments

Comments
 (0)