Skip to content

Form values don't get reinitialized from defaults when toggling between anyOf/oneOf options #3736

@mbalc

Description

@mbalc

Prerequisites

  • I have searched the existing issues
    I understand that providing a SSCCE example is tremendously useful to the maintainers.
    I have read the documentation
    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.x

Current Behavior

When one of the options from anyOf/oneOf is rendered, the default values get set properly. However, after you switch to a different option, then go back, all the defaults will be gone.

Expected Behavior

The defaults should get set every time someone changes the subschema version

Steps To Reproduce

  1. Go to https://rjsf-team.github.io/react-jsonschema-form/
  2. Click the "Any Of" example
  3. Notice that "First method of identification" is selected, and "First name" is set to the default value, "Chuck"
  4. In the render view, change to "Second method of identification"
  5. In the render view, change to "First method of identification"

Current: "First name" is empty
Expected: "First name" is set to the default value, "Chuck"

Environment

- OS: Windows 11
- Node & npm: whatever you use on your playground

Anything else?

image

Activity

added
needs triageInitial label given, to be assigned correct labels and assigned
on Jun 19, 2023
mbalc

mbalc commented on Jun 19, 2023

@mbalc
Author

nevermind, there's this "Object fields default behavior" thing that you need to change to a different value; maybe consider making it a bit more obvious that this works this way - and consider changing the default value there in the playground away from the legacy option - and you can probably close this issue

nickgros

nickgros commented on Jun 23, 2023

@nickgros
Contributor

@mbalc thanks for the report. The "legacy" behavior is the default in RJSF v5 (it will be changed in in the next major version), so will probably change the default value when v6 is released.

I would actually expect the firstName field to re-populate with the default value under legacy behavior, so I think this is a bug.

added
any-one-all-ofRelated to fixing anyOf, oneOf or allOf
and removed
needs triageInitial label given, to be assigned correct labels and assigned
on Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mbalc@nickgros

        Issue actions

          Form values don't get reinitialized from defaults when toggling between anyOf/oneOf options · Issue #3736 · rjsf-team/react-jsonschema-form