Skip to content

Switching between two oneOf option returns undefined form data #4314

@altpd13

Description

@altpd13

Prerequisites

What theme are you using?

core

Version

5.2.0

Current Behavior

Using this json Schema

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "ExecuteMsg",
  "oneOf": [
    {
      "type": "object",
      "required": [
        "increment"
      ],
      "properties": {
        "increment": {
          "type": "object"
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "reset"
      ],
      "properties": {
        "reset": {
          "type": "object",
          "required": [
            "count"
          ],
          "properties": {
            "count": {
              "type": "integer",
              "format": "int32"
            }
          }
        }
      },
      "additionalProperties": false
    }
  ]
}

when form is first initialized formData is {increment: {}} and when I change to reset formData is set to {increment: undefined, reset: {}} and again when change to increment formData is {increment: undefined, reset: undefined}

Expected Behavior

When changing back to option increment It should be {increment: {}} not {increment: undefined, reset: undefined}

Steps To Reproduce

https://rjsf-team.github.io/react-jsonschema-form/#eyJmb3JtRGF0YSI6eyJyZXNldCI6e319LCJzY2hlbWEiOnsiJHNjaGVtYSI6Imh0dHA6Ly9qc29uLXNjaGVtYS5vcmcvZHJhZnQtMDcvc2NoZW1hIyIsInRpdGxlIjoiRXhlY3V0ZU1zZyIsIm9uZU9mIjpbeyJ0eXBlIjoib2JqZWN0IiwicmVxdWlyZWQiOlsiaW5jcmVtZW50Il0sInByb3BlcnRpZXMiOnsiaW5jcmVtZW50Ijp7InR5cGUiOiJvYmplY3QifX0sImFkZGl0aW9uYWxQcm9wZXJ0aWVzIjpmYWxzZX0seyJ0eXBlIjoib2JqZWN0IiwicmVxdWlyZWQiOlsicmVzZXQiXSwicHJvcGVydGllcyI6eyJyZXNldCI6eyJ0eXBlIjoib2JqZWN0IiwicmVxdWlyZWQiOlsiY291bnQiXSwicHJvcGVydGllcyI6eyJjb3VudCI6eyJ0eXBlIjoiaW50ZWdlciIsImZvcm1hdCI6ImludDMyIn19fX0sImFkZGl0aW9uYWxQcm9wZXJ0aWVzIjpmYWxzZX1dfSwidWlTY2hlbWEiOnt9LCJ0aGVtZSI6ImRlZmF1bHQiLCJsaXZlU2V0dGluZ3MiOnsic2hvd0Vycm9yTGlzdCI6InRvcCIsImV4cGVyaW1lbnRhbF9kZWZhdWx0Rm9ybVN0YXRlQmVoYXZpb3IiOnsiYXJyYXlNaW5JdGVtcyI6eyJwb3B1bGF0ZSI6InBvcHVsYXRlIiwibWVyZ2VFeHRyYURlZmF1bHRzIjpmYWxzZX0sImFsbE9mIjoic2tpcERlZmF1bHRzIiwiZW1wdHlPYmplY3RGaWVsZHMiOiJwb3B1bGF0ZUFsbERlZmF1bHRzIn0sImxpdmVWYWxpZGF0ZSI6ZmFsc2V9fQ==

Environment

- OS: Mac Sonoma 14.5
- Node: 20.0.0
- npm: 9.6.4
- yarn: 1.22.22

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions