@rjsf/utils 5.22.3 → 5.22.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +9 -4
- package/dist/index.js.map +2 -2
- package/dist/utils.esm.js +9 -4
- package/dist/utils.esm.js.map +2 -2
- package/dist/utils.umd.js +9 -4
- package/lib/schema/getDefaultFormState.js +12 -5
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/schema/getDefaultFormState.ts +13 -5
|
@@ -432,11 +432,14 @@ export function getArrayDefaults<T = any, S extends StrictRJSFSchema = RJSFSchem
|
|
|
432
432
|
): T | T[] | undefined {
|
|
433
433
|
const schema: S = rawSchema;
|
|
434
434
|
|
|
435
|
-
const
|
|
436
|
-
const
|
|
435
|
+
const arrayMinItemsStateBehavior = experimental_defaultFormStateBehavior?.arrayMinItems ?? {};
|
|
436
|
+
const { populate: arrayMinItemsPopulate, mergeExtraDefaults: arrayMergeExtraDefaults } = arrayMinItemsStateBehavior;
|
|
437
|
+
|
|
438
|
+
const neverPopulate = arrayMinItemsPopulate === 'never';
|
|
439
|
+
const ignoreMinItemsFlagSet = arrayMinItemsPopulate === 'requiredOnly';
|
|
440
|
+
const isPopulateAll = arrayMinItemsPopulate === 'all' || (!neverPopulate && !ignoreMinItemsFlagSet);
|
|
441
|
+
const computeSkipPopulate = arrayMinItemsStateBehavior?.computeSkipPopulate ?? (() => false);
|
|
437
442
|
const isSkipEmptyDefaults = experimental_defaultFormStateBehavior?.emptyObjectFields === 'skipEmptyDefaults';
|
|
438
|
-
const computeSkipPopulate =
|
|
439
|
-
experimental_defaultFormStateBehavior?.arrayMinItems?.computeSkipPopulate ?? (() => false);
|
|
440
443
|
|
|
441
444
|
const emptyDefault = isSkipEmptyDefaults ? undefined : [];
|
|
442
445
|
|
|
@@ -460,7 +463,7 @@ export function getArrayDefaults<T = any, S extends StrictRJSFSchema = RJSFSchem
|
|
|
460
463
|
if (neverPopulate) {
|
|
461
464
|
defaults = rawFormData;
|
|
462
465
|
} else {
|
|
463
|
-
|
|
466
|
+
const itemDefaults = rawFormData.map((item: T, idx: number) => {
|
|
464
467
|
return computeDefaults<T, S, F>(validator, schemaItem, {
|
|
465
468
|
rootSchema,
|
|
466
469
|
_recurseList,
|
|
@@ -470,6 +473,11 @@ export function getArrayDefaults<T = any, S extends StrictRJSFSchema = RJSFSchem
|
|
|
470
473
|
required,
|
|
471
474
|
});
|
|
472
475
|
}) as T[];
|
|
476
|
+
|
|
477
|
+
// If the populate 'requiredOnly' flag is set then we only merge and include extra defaults if they are required.
|
|
478
|
+
// Or if populate 'all' is set we merge and include extra defaults.
|
|
479
|
+
const mergeExtraDefaults = ((ignoreMinItemsFlagSet && required) || isPopulateAll) && arrayMergeExtraDefaults;
|
|
480
|
+
defaults = mergeDefaultsWithFormData(defaults, itemDefaults, mergeExtraDefaults);
|
|
473
481
|
}
|
|
474
482
|
}
|
|
475
483
|
|