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

oneOf not selecting correct option for objects with the same property keys but different default, read-only values #2069

Closed
3 tasks done
zmagauina-fn opened this issue Sep 24, 2020 · 1 comment
Labels
any-one-all-of Related to fixing anyOf, oneOf or allOf bug core

Comments

@zmagauina-fn
Copy link
Contributor

Prerequisites

Description

A oneOf schema with two objects with the same property but different read-only, default values won't correctly select the option with the matching value for the key when passed a formData, and instead will match the first option with the correct property keys (both the property keys are the same).

Steps to Reproduce

In this playground example, you can see that the two oneOf options both have the same properties (one "lorem" key), with different read-only, default values.
2. If you select the second option, it will update formData to { "lorem": "second" }. If you select the first option, formData becomes { "lorem": "first" }. This is the expected behavior.
3. If you now change formData to { "lorem": "second" }, it will keep the selector on the first option, but change the name to "second".

Expected behavior

Per the example above, I'm trying to initialize the selector on the second option using the formData value.

I have data objects with the same keys but different default, read-only values that represent different options. I want to be able to initialize the selector at the correct option based on the formData passed in.

Actual behavior

The isValid check inside the getMatchingOption method in utils will return true when comparing the following schema:

{
    "properties": {
        "lorem": {
            "type": "string",
            "default": "first",
            "readOnly": true
        }
    },
    "required": [
        "lorem"
    ]
}

and formData:

{
  "lorem": "second"
}

Even though the it's a default, read-only value and the values don't match.

Version

"@rjsf/core": "^2.4.0"
@zmagauina-fn zmagauina-fn changed the title oneOf schema not selecting correct option for objects with the same property keys but different default, read-only values oneOf not selecting correct option for objects with the same property keys but different default, read-only values Sep 24, 2020
@yair-dana
Copy link

I had the same problem.
after I used 'const' instead 'readonly' it works

const: 'second'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
any-one-all-of Related to fixing anyOf, oneOf or allOf bug core
Projects
None yet
Development

No branches or pull requests

4 participants