Skip to content

Commit 3f295ab

Browse files
committed
fixed array const populate values
1 parent 3aff670 commit 3f295ab

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

packages/utils/src/schema/getDefaultFormState.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -459,13 +459,17 @@ export function getArrayDefaults<T = any, S extends StrictRJSFSchema = RJSFSchem
459459
}
460460
}
461461

462-
if (neverPopulate) {
463-
return defaults ?? emptyDefault;
464-
}
465-
if (ignoreMinItemsFlagSet && !required) {
466-
// If no form data exists or defaults are set leave the field empty/non-existent, otherwise
467-
// return form data/defaults
468-
return defaults ? defaults : undefined;
462+
// Check if the schema has a const property defined, then we should always return the computedDefault since it's coming from the const.
463+
const hasConst = isObject(schema) && CONST_KEY in schema;
464+
if (hasConst) {
465+
if (neverPopulate) {
466+
return defaults ?? emptyDefault;
467+
}
468+
if (ignoreMinItemsFlagSet && !required) {
469+
// If no form data exists or defaults are set leave the field empty/non-existent, otherwise
470+
// return form data/defaults
471+
return defaults ? defaults : undefined;
472+
}
469473
}
470474

471475
const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;

0 commit comments

Comments
 (0)