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

Switching between two oneOf option returns undefined form data #4314

Open
4 tasks done
altpd13 opened this issue Sep 26, 2024 · 2 comments
Open
4 tasks done

Switching between two oneOf option returns undefined form data #4314

altpd13 opened this issue Sep 26, 2024 · 2 comments
Labels
bug needs triage Initial label given, to be assigned correct labels and assigned

Comments

@altpd13
Copy link

altpd13 commented Sep 26, 2024

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

@altpd13 altpd13 added bug needs triage Initial label given, to be assigned correct labels and assigned labels Sep 26, 2024
@altpd13 altpd13 changed the title <title> Switching between two oneOf option returns undefined form data Switching between two oneOf option returns undefined form data Sep 26, 2024
@nickgros
Copy link
Contributor

Looks like a duplicate of #3711 ?

@altpd13
Copy link
Author

altpd13 commented Sep 30, 2024

Thank you @nickgros for reading my issue
But I'm afraid the behavior #3711 is different from my behavior.

The current behavior I've mentioned is when changing back to oneOf element which requires empty object property results undefined value.
So for example I want a formData that have empty value(e.g {increment: {}} on submit. The initial formData when Form first renders is set as exactly what I wanted it to be({increment: {}}). But changing to other oneOf element and changing back to increment element will set the formData to {increment: undefined, reset: undefined} not {increment: {}, reset: undefined}.

I wish this information would helps you understand

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug needs triage Initial label given, to be assigned correct labels and assigned
Projects
None yet
Development

No branches or pull requests

2 participants