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

Default value not prefilled when object with if/then is wrapped to another object #4222

Open
4 tasks done
rap1ds opened this issue Jun 17, 2024 · 2 comments
Open
4 tasks done
Labels
bug defaults help wanted if-then-else Issues related to handling JSON Schema if/then/else

Comments

@rap1ds
Copy link

rap1ds commented Jun 17, 2024

Prerequisites

What theme are you using?

core

Version

5.x (current Playground version)

Current Behavior

I have a schema with type: object and if/then conditionally adding a new property with a default value. This works as expected. But if I wrap the whole schema in a wrapping object, the default value prefilling no longer works.

Expected Behavior

  1. Open this Playground example
  2. Click "checkbox"

Expected: A required field "foo" appears with default value "foo default value"

Actual: A required field "foo" appears with default value "foo default value"

I would expect that the same default behaviour happens even if the object is wrapped in another object.

Steps To Reproduce

  1. Open this Playground example which is the exact same schema as above but it's wrapped in a wrappingObject.
  2. Click "checkbox"

Expected: A required field "foo" appears with default value "foo default value"

Actual: A required field "foo" appears with NO default value.

Environment

- Mac
- Google Chrome Version 125.0.6422.142 (Official Build) (arm64)
- Playground

Anything else?

Playground options

Playground has multiple options that control default behaviour:

  • Populate minItems in arrays
  • allOf defaults behaviour
  • Object fields default behavior

I tried changing all these settings but none of them didn't solve the issue.

Duplicate?

Here's another open issue that looks very similar: #3599

It's similar because in #3599 the default behaviour seems to be first as expected, but when wrapped in an object, default prefilling is not working anymore. It's different in a sense that #3599 is about allOf but this bug is about if/then/else.

Feel free to close this one if you think this is duplicate of #3599

@rap1ds rap1ds added bug needs triage Initial label given, to be assigned correct labels and assigned labels Jun 17, 2024
@nickgros
Copy link
Contributor

This is definitely a bug and we would appreciate a pull request to fix it. I just closed #3599 because I think that was fixed in #3969.

Interestingly, if you wrap if/then/else in allOf, it works. So that may be a useful workaround for you. See this playground link.

@nickgros nickgros added help wanted defaults if-then-else Issues related to handling JSON Schema if/then/else and removed needs triage Initial label given, to be assigned correct labels and assigned labels Jun 21, 2024
@rap1ds
Copy link
Author

rap1ds commented Jun 28, 2024

Thanks for the workaround! The workaround seems to work fine when the "allOf defaults behaviour" is set to "Populate defaults with allOf"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug defaults help wanted if-then-else Issues related to handling JSON Schema if/then/else
Projects
None yet
Development

No branches or pull requests

2 participants