react-jsonschema-form
react-jsonschema-form copied to clipboard
Array defaults don't work at the root of the schema.
Prerequisites
- [X] I have searched the existing issues
- [X] I understand that providing a SSCCE example is tremendously useful to the maintainers.
- [X] I have read the documentation
- [X] Ideally, I'm providing a sample JSFiddle, Codesandbox.io or preferably a shared playground link demonstrating the issue.
What theme are you using?
core
Version
5.21.2
Current Behavior
Array defaults don't work at the root of the schema.
Expected Behavior
Array defaults should work at the root of the schema and not only when it's nested.
Steps To Reproduce
- Click here open the demo with array at the root of the schema
- You'll notice that defaults are not applied.
- Click here to open the demo with nested array.
- You'll notice that defaults are applied when the array is nested and not at the root of the schema.
Environment
- OS: macOS
- Node: 22.1.0
- npm: 10.7.0
Anything else?
No response
@abdalla-rko Another interesting bug with our defaulting code. Are you able to fix this for us?
This is not an issue. It was not applying the defaults because the formData has an empty array and the array mergeExtraDefaults was not enabled. But there is an issue when you enable the mergeExtraDefaults and you have formData as an empty array, the default on the root of the array schema doesn't get applied and only applies the default from the items property (see demo). If formData is undefined or null, it will apply the default from the root schema and items.default and the root default will take precedence over item default.