Skip to content

Issue with nested if...then conditions #4450

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

Open
4 tasks done
anya92 opened this issue Jan 15, 2025 · 9 comments
Open
4 tasks done

Issue with nested if...then conditions #4450

anya92 opened this issue Jan 15, 2025 · 9 comments

Comments

@anya92
Copy link

anya92 commented Jan 15, 2025

Prerequisites

What theme are you using?

core

Version

5.24.1

Current Behavior

There is a problem with nested if...then conditions inside properties. With liveOmit and omitExtraData enabled, the value of a property that is displayed conditionally is automatically removed.

Here is the JSON schema I am testing:

{
  "type": "object",
  "properties": {
    "object": {
      "title": "Object",
      "type": "object",
      "properties": {
        "name": {
          "title": "Name",
          "type": "string"
        },
        "booleanProperty": {
          "title": "Boolean Property",
          "default": true,
          "type": "boolean"
        }
      },
      "if": {
        "properties": {
          "booleanProperty": {
            "const": true
          }
        }
      },
      "then": {
        "properties": {
          "otherProperty": {
            "title": "Other Property",
            "type": "string",
            "enum": [
              "Hello",
              "World"
            ]
          }
        },
        "required": [
          "otherProperty"
        ]
      }
    }
  }
}

When the booleanProperty is set to true, the otherProperty field is displayed in the form, but its value cannot be changed because it is automatically cleared.

Expected Behavior

The value of otherProperty should not be cleared when booleanProperty is set to true.

Steps To Reproduce

  1. Go to Playground.
  2. Try to change Other Property value.

Environment

- OS:
- Node:
- npm:

Anything else?

No response

@anya92 anya92 added bug needs triage Initial label given, to be assigned correct labels and assigned labels Jan 15, 2025
@heath-freenome
Copy link
Member

heath-freenome commented Jan 17, 2025

Essentially a re-open of #4109. @anya92 do you feel comfortable updating the fix the @helen-m-lin provided? Or maybe they can continue improving the fix?

@heath-freenome heath-freenome added help wanted and removed needs triage Initial label given, to be assigned correct labels and assigned labels Jan 17, 2025
@anya92
Copy link
Author

anya92 commented Feb 25, 2025

Thanks for the update. I think it would be best if @helen-m-lin continues with the fix, given their familiarity with the issue.

@helen-m-lin
Copy link
Contributor

@anya92 @heath-freenome I can try to take a look next week. Thanks!

@anya92
Copy link
Author

anya92 commented Mar 26, 2025

Hey @helen-m-lin, any updates on this? Thanks!

@helen-m-lin
Copy link
Contributor

Hi @anya92, unfortunately I haven't had the chance to look into this issue. If this is urgent maybe someone else can take a look?

@shivsperfect
Copy link

HI @anya92 @helen-m-lin I looked into the issue, I have one clarification

from provided schema if we wrap if then inside the allOff it works just fine with live omit

example:
{
  "allOf": [
    {
      "if": {
        "properties": {
          "booleanProperty": {
            "const": true
          }
        }
      },
      "then": {
        "properties": {
          "otherProperty": {
            "title": "Other Property",
            "type": "string",
            "enum": [
              "Hello",
              "World"
            ]
          }
        },
        "required": [
          "otherProperty"
        ]
      }
    }
  ]
}

Are you guys expecting fix without changing the schema ? please let me know

Fyi @heath-freenome

@anya92
Copy link
Author

anya92 commented Mar 29, 2025

Hi @shivsperfect!

Yes, I know that wrapping if-then inside allOf is a workaround, but I need a fix without changing the schema. The schema I provided (without anyOf) worked before, but it stopped working after a package release in the past. I already have existing schemas that my users created, so I can't update the rjsf package because it would break them in my application.

@shivsperfect
Copy link

sure @anya92 I will work on the fix, thanks for the context

@anya92
Copy link
Author

anya92 commented Apr 16, 2025

Hi @shivsperfect, do you have any updates?

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

No branches or pull requests

4 participants