Skip to content

Commit f002aba

Browse files
author
Ruben van Leeuwen
committed
1954: Added a comment with explanation
1 parent 0415932 commit f002aba

File tree

1 file changed

+8
-1
lines changed
  • frontend/packages/pydantic-forms/src

1 file changed

+8
-1
lines changed

frontend/packages/pydantic-forms/src/utils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ export const itemizeArrayItem = (
9494
return itemize(item, itemId);
9595
};
9696

97+
/**
98+
* This functions returns a fields value but taking into account the position
99+
* of the field in any tree it might be in. For example when requesting the
100+
* 'age' field it will return the sibling field called 'age'. This is relevant
101+
* if the field is part of an array or object where there might be more 'age'
102+
* fields on other levels
103+
* */
97104
export function getFormFieldValue(
98105
fieldName: string,
99106
formValues: FieldValues,
@@ -103,7 +110,7 @@ export function getFormFieldValue(
103110
let current: FieldValues = { ...formValues };
104111

105112
for (const segment of pathToParent) {
106-
// Try to convert numeric strings to numbers for array indexing
113+
// Convert numeric strings to numbers for array indexing
107114
const key = isNaN(Number(segment)) ? segment : Number(segment);
108115
if (current && key in current) {
109116
current = current[key];

0 commit comments

Comments
 (0)