Skip to content

Can't use default object with enum object (Radio list) #4635

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

Closed
4 tasks done
rmaury opened this issue May 21, 2025 · 3 comments · Fixed by #4637
Closed
4 tasks done

Can't use default object with enum object (Radio list) #4635

rmaury opened this issue May 21, 2025 · 3 comments · Fixed by #4637

Comments

@rmaury
Copy link

rmaury commented May 21, 2025

Prerequisites

What theme are you using?

core

Version

5.24.x

Current Behavior

I'm currently having an issue after updating my version of react-json-schema.
Before that, I could create a radio element with a list of object in enum, and a default object to initialize.

Example :

"example": {
      "title": "Radio with object",
      "default": {
        "label": "First element",
        "value": "one"
      },
      "enum": [
          {
          "label": "First element",
          "value": "one"
        },
        {
          "label": "Second element",
          "value": "two"
        },
        {
          "label": "Third element",
          "value": "three"
        }
      ],
      "minItems": 1,
      "maxItems": 1,
    }

Since I've updated to 5.24.x, if the default value is an object, I can't select other option in the rendered Radio Element.
I have to delete the default from jsonSchema to make it works.

Do you have any idea to get a default value with a list of object in enum ?
Or is that a bad practice and this is something you don't allow anymore ?

Expected Behavior

Select other item in rendered view when I've set a default value with an object

Steps To Reproduce

You can test it in :

https://rjsf-team.github.io/react-jsonschema-form/
-> Enumerated Objects
-> just add this in properties -> locationRadio
"default": { "name": "New York", "lat": 40, "lon": 74 }

And try to select Amsterdam on the rendered part.
You can't

Environment

- OS: Ubuntu
- Node: 22
- npm:

Anything else?

Image
(can't select Amsterdam on right part after adding a default value)

@rmaury rmaury added bug needs triage Initial label given, to be assigned correct labels and assigned labels May 21, 2025
@foyarash
Copy link
Contributor

I encountered the same issue. Upon searching, I found out that this comes from here, where the condition should be overrideFormDataWithDefaults && (keyExistsInDefaults && !keyExistsInFormData) (instead of the ||). However, upon working on making a PR, it seems to break some tests, so I guess this have quite a lot of impacts.

@rmaury
Copy link
Author

rmaury commented May 21, 2025

I encountered the same issue. Upon searching, I found out that this comes from here, where the condition should be overrideFormDataWithDefaults && (keyExistsInDefaults && !keyExistsInFormData) (instead of the ||). However, upon working on making a PR, it seems to break some tests, so I guess this have quite a lot of impacts.

Thanks !
So I'll wait a few days to see if contributors respond, otherwise I'll maybe search a solution with what you've tried to do too :)

@heath-freenome heath-freenome added help wanted and removed needs triage Initial label given, to be assigned correct labels and assigned labels May 23, 2025
@heath-freenome
Copy link
Member

@foyarash Thanks for the fix! Please respond to the comment I left you in your PR

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