Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ should change the heading of the (upcoming) version to include a major version b
## @rjsf/utils

- Added support for rendering `ui:help` as markdown via new `ui:enableMarkdownInHelp` flag in `FieldHelpTemplate`
- Fixed issue with schema array with nested dependent fixed-length, fixing [#3754](https://github.com/rjsf-team/react-jsonschema-form/issues/3754)


# 6.0.2
Expand Down
2 changes: 2 additions & 0 deletions packages/utils/src/schema/getDefaultFormState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,12 +614,14 @@ export function getArrayDefaults<T = any, S extends StrictRJSFSchema = RJSFSchem
if (Array.isArray(defaults)) {
defaults = defaults.map((item, idx) => {
const schemaItem: S = getInnerSchemaForArrayItem<S>(schema, AdditionalItemsHandling.Fallback, idx);
const itemFormData = Array.isArray(rawFormData) ? rawFormData[idx] : undefined;
return computeDefaults<T, S, F>(validator, schemaItem, {
rootSchema,
_recurseList,
experimental_defaultFormStateBehavior,
experimental_customMergeAllOf,
parentDefaults: item,
rawFormData: itemFormData,
required,
shouldMergeDefaultsIntoFormData,
initialDefaultsGenerated,
Expand Down
104 changes: 104 additions & 0 deletions packages/utils/test/schema/getDefaultFormStateTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1870,6 +1870,110 @@ export default function getDefaultFormStateTest(testValidator: TestValidatorType
});
});

describe('array with nested dependent fixed-length array schema', () => {
const schema: RJSFSchema = {
items: [
{
dependencies: {
checkbox: {
if: {
properties: {
checkbox: {
const: true,
},
},
},
then: {
properties: {
inner_array: {
items: [
{
title: 'Fixed Item',
type: 'string',
},
],
title: 'Inner Fixed-Length Array',
type: 'array',
},
},
},
},
},
properties: {
checkbox: {
title: 'Dependency Checkbox',
type: 'boolean',
},
},
title: 'Outer Item',
type: 'object',
},
],
title: 'Outer Fixed Length Array',
type: 'array',
};
const formData = [{ checkbox: true }];
const includeUndefinedValues = 'excludeObjectChildren';
const expected = [
{
checkbox: true,
inner_array: [undefined],
},
];

test('getDefaultFormState', () => {
expect(getDefaultFormState(testValidator, schema, formData, schema, includeUndefinedValues)).toEqual(
expected,
);
});

test('computeDefaults', () => {
expect(
computeDefaults(testValidator, schema, {
rootSchema: schema,
rawFormData: formData,
includeUndefinedValues,
shouldMergeDefaultsIntoFormData: true,
}),
).toEqual(expected);
});

test('getDefaultBasedOnSchemaType', () => {
expect(
getDefaultBasedOnSchemaType(
testValidator,
schema,
{
rootSchema: schema,
includeUndefinedValues,
},
[
{
checkbox: true,
},
],
),
).toEqual(expected);
});

test('getArrayDefaults', () => {
expect(
getArrayDefaults(
testValidator,
schema,
{
rootSchema: schema,
includeUndefinedValues,
},
[
{
checkbox: true,
},
],
),
).toEqual(expected);
});
});
describe('an invalid array schema', () => {
const schema: RJSFSchema = {
type: 'array',
Expand Down
Loading