Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array defaults don't work at the root of the schema. #4335

Open
4 tasks done
abdalla-rko opened this issue Oct 12, 2024 · 2 comments · May be fixed by #4359
Open
4 tasks done

Array defaults don't work at the root of the schema. #4335

abdalla-rko opened this issue Oct 12, 2024 · 2 comments · May be fixed by #4359

Comments

@abdalla-rko
Copy link
Contributor

abdalla-rko commented Oct 12, 2024

Prerequisites

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

  1. Click here open the demo with array at the root of the schema
  2. You'll notice that defaults are not applied.
  3. Click here to open the demo with nested array.
  4. 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 abdalla-rko added bug needs triage Initial label given, to be assigned correct labels and assigned labels Oct 12, 2024
@heath-freenome heath-freenome added help wanted and removed needs triage Initial label given, to be assigned correct labels and assigned labels Oct 18, 2024
@heath-freenome
Copy link
Member

@abdalla-rko Another interesting bug with our defaulting code. Are you able to fix this for us?

@abdalla-rko
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants