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

anyOf/oneOf keeping undefined property of old option #3711

Open
4 tasks done
cwendtxealth opened this issue May 31, 2023 · 1 comment · May be fixed by #3714
Open
4 tasks done

anyOf/oneOf keeping undefined property of old option #3711

cwendtxealth opened this issue May 31, 2023 · 1 comment · May be fixed by #3714

Comments

@cwendtxealth
Copy link
Contributor

Prerequisites

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

@cwendtxealth cwendtxealth added bug needs triage Initial label given, to be assigned correct labels and assigned labels May 31, 2023
@cwendtxealth cwendtxealth linked a pull request Jun 1, 2023 that will close this issue
8 tasks
@heath-freenome heath-freenome added help wanted and removed needs triage Initial label given, to be assigned correct labels and assigned labels Jun 2, 2023
@michal-kurz
Copy link
Contributor

The leftover undefined value also prevents adoption of default values, if the item gets re-selected again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants