react-jsonschema-form icon indicating copy to clipboard operation
react-jsonschema-form copied to clipboard

Combination of `anyOf`/`allOf` does not retain the correct option defaults

Open linas-vii opened this issue 5 years ago • 2 comments

Prerequisites

Description

When having a combination of anyOf/allOf, the generated default option for anyOf is not retained correctly from the form data.

See this link in CodeSandbox for an example.

Playground example

Steps to Reproduce

  1. Open the example.
  2. Choose a variable and change it from Baz to Bax.
  3. Change tabs from Form to JSON, and back again from JSON to Form.

Expected behavior

The option for a variable selected is retained between the tab changes.

Actual behavior

The option for a variable selected is always changed to the first option (in this case Baz).

Version

2.4.0

Additional details:

I tried to debug this issue, and there are certain points which might be the cause, but please correct me if I have misunderstood something here:

  • In core/src/util.js:224, getMatchingOption is being passed formData as undefined, shouldn’t it just pass the formData as it is?
  • In core/src/util.js:1179, shouldn’t the option be resolved first with resolveSchema(option, schema, formData) in order to have all $ref's resolved before performing validation at core/src/util.js:1222 and core/src/util.js:1225?

Related issues/PRs:

PRs:

https://github.com/rjsf-team/react-jsonschema-form/pull/1564

linas-vii avatar Sep 25 '20 10:09 linas-vii

I reproduced this issue using only allOf (without combining it with anyOf): Playground.

I copied the example from the official Json Schema documentation but added defaults.

Expected: Form should show defaults for both addresses. Actual: Form only shows defaults for the address not using allOf.

marian2js avatar Oct 22 '20 00:10 marian2js

This issue has been automatically marked as possibly close because it has not had recent activity. It will be closed if no further activity occurs. Please leave a comment if this is still an issue for you. Thank you.

stale[bot] avatar Apr 25 '24 23:04 stale[bot]

This issue was closed because of lack of recent activity. Reopen if you still need assistance.

stale[bot] avatar May 26 '24 00:05 stale[bot]