Skip to content

anyOf/oneOf keeping undefined property of old option #3711

Open
@cwendtxealth

Description

@cwendtxealth
Contributor

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 editing a field in oneOf/anyOf property and then switching to the other schema, the formData still keeps the old property but as undefined. This causes issues when submitting the form and the schema has set additionalProperties: false. Here is a simple rjsf playground and example schema:

{
  "type": "object",
  "anyOf": [
    {
      "additionalProperties": false,
      "properties": {
        "lorem": {
          "type": "string"
        }
      }
    },
    {
      "additionalProperties": false,
      "properties": {
        "ipsum": {
          "type": "string"
        }
      }
    }
  ]
}

The function sanitizeDataForNewSchema is where the old formData fields are set to undefined. I think a simple solution would be to filter out all undefined fields after all the logic in sanitizeDataForNewSchema is done.

Expected Behavior

When switching to other schema it would clear out any old fields.

Steps To Reproduce

No response

Environment

- OS:
- Node:
- npm:

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @heath-freenome@cwendtxealth@michal-kurz

      Issue actions

        anyOf/oneOf keeping undefined property of old option · Issue #3711 · rjsf-team/react-jsonschema-form