You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And given the raw form data with a value of {},
I believe the resulting data after processing the default values should be { optionalArray: undefined } since the optionalArray property is declared in the schema hence I guess we expect to have in our resulting data, but with a value of undefined since it's optional. ajv would consider the data as valid in that case.
As you can see in the playground, the value returned is:
{
"optionalArray": [
null,
null
]
}
And when running the following test
it('should return partial array for an optional array property with minItems when provided with a partial array', () => {
const schema: RJSFSchema = {
type: 'object',
properties: {
optionalArray: {
type: 'array',
minItems: 2,
items: { type: 'string' },
},
},
};
expect(
computeDefaults(testValidator, schema, {
rootSchema: schema,
rawFormData: {},
behaviorBitFlags: DefaultFormStateBehavior.IgnoreMinItemsUnlessRequired,
})
).toEqual({ optionalArray: undefined });
});
in getDefaultFormStateTest.ts, we have the following result:
{
"optionalArray": [
undefined,
undefined
]
}
I guess this is because I'm running this test on the latest version of the codebase and the playground might be using the latest release.
In any case, the issue is there.
Expected Behavior
This test should pass:
it('should return partial array for an optional array property with minItems when provided with a partial array', () => {
const schema: RJSFSchema = {
type: 'object',
properties: {
optionalArray: {
type: 'array',
minItems: 2,
items: { type: 'string' },
},
},
};
expect(
computeDefaults(testValidator, schema, {
rootSchema: schema,
rawFormData: {},
behaviorBitFlags: DefaultFormStateBehavior.IgnoreMinItemsUnlessRequired,
})
).toEqual({ optionalArray: undefined });
});
anthonycaron
changed the title
default value of an optional array with minItems and no default for the items
default value of an optional array with minItems and no default for the items is incorrect
May 10, 2023
anthonycaron
changed the title
default value of an optional array with minItems and no default for the items is incorrect
incorrect default value for an optional array with minItems and no default for the items
May 10, 2023
Just for context, there's a discussion regarding this here.
anthonycaron
changed the title
incorrect default value for an optional array with minItems and no default for the items
incorrect default value for an array with minItems and no default for the items
May 11, 2023
@anthonycaron The playground editors will convert the [undefined, undefined] array into [null, null] so that is expected behavior. Also, once we release 5.7.0 (soon!), the new experimental_DefaultFormStateBehavior.arrayMinItems: 'requiredOnly' flag being added to the Form could also fix this. Would you be willing to take another look at this once we release?
Prerequisites
What theme are you using?
core
Version
latest
Current Behavior
Given this schema:
And given the raw form data with a value of
{}
,I believe the resulting data after processing the default values should be
{ optionalArray: undefined }
since theoptionalArray
property is declared in the schema hence I guess we expect to have in our resulting data, but with a value ofundefined
since it's optional.ajv
would consider the data as valid in that case.As you can see in the playground, the value returned is:
And when running the following test
in
getDefaultFormStateTest.ts
, we have the following result:I guess this is because I'm running this test on the latest version of the codebase and the playground might be using the latest release.
In any case, the issue is there.
Expected Behavior
This test should pass:
Steps To Reproduce
You can try it in the playground
Or
npm i
packages/utils/test/schema/getDefaultFormStateTest.ts
filenpm run test
Environment
Anything else?
No response
The text was updated successfully, but these errors were encountered: