Skip to content

Commit

Permalink
Retrieve correct default value #872
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Oct 23, 2024
1 parent bc0f2e7 commit b9b927c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/utils/fieldWhenClause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export const fieldWhenClause = (field: Field, parent: IMetadata, allFields?: Fie
return true;
}

// eslint-disable-next-line no-debugger
debugger;

const parentField = allFields?.find((f) => f.name === when.fieldRef);
if (parentField && parentField.when) {
const renderParent = fieldWhenClause(parentField, parent, allFields);
Expand All @@ -23,9 +26,16 @@ export const fieldWhenClause = (field: Field, parent: IMetadata, allFields?: Fie
}

let whenValue = parent[when.fieldRef];
if (whenValue === undefined) {
whenValue = field.default as string | IMetadata | string[] | null;

// If the value is not yet set, check if the field has a default value.
if (
typeof whenValue === 'undefined' &&
parentField &&
typeof parentField.default !== 'undefined'
) {
whenValue = parentField.default as string | IMetadata | string[] | null;
}

if (when.caseSensitive || typeof when.caseSensitive === 'undefined') {
return caseSensitive(when, field, whenValue);
} else {
Expand Down

0 comments on commit b9b927c

Please sign in to comment.