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

Cannot change property value with liveOmit and omitExtraData for arrays of objects and conditionality #4109

Closed
4 tasks done
anya92 opened this issue Feb 28, 2024 · 10 comments · Fixed by #4228
Closed
4 tasks done

Comments

@anya92
Copy link

anya92 commented Feb 28, 2024

Prerequisites

What theme are you using?

core

Version

5.x

Current Behavior

I have a problem when trying to change property values using "liveOmit" and "omitExtraData". This is the JSON schema I use:

{
  "title": "Schema",
  "type": "object",
  "properties": {
    "array_of_objects": {
      "title": "Array of Objects",
      "type": "array",
      "items": {
        "$ref": "#/definitions/myArrayOfObjects"
      },
      "minItems": 1
    }
  },
  "definitions": {
    "myArrayOfObjects": {
      "title": "Array Item",
      "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"
        ]
      },
      "required": [
        "name"
      ]
    }
  }
}

Expected Behavior

It should be possible to change the otherProperty value.

Steps To Reproduce

  1. Go to the rjsf playground
  2. liveOmit and omitExtraData are already turned on, liveValidation is also turned on to see that the condition is valid
  3. try to change value of Other Property - nothing happens

Environment

- OS: macOS 14.2.1
- Node: 18.14.2
- npm: 9.5.0

Anything else?

It works in my project which uses version 5.12.1. But I can't update the package after it stopped working.
I already addressed this issue in #3909.

@anya92 anya92 added bug needs triage Initial label given, to be assigned correct labels and assigned labels Feb 28, 2024
@heath-freenome
Copy link
Member

heath-freenome commented Mar 1, 2024

@anya92 It seems like when you turn off omitExtraData everything works fine. This is a duplicate of #2720 (we'll close that one as a duplicate of yours), although your use-case is much clearer. Is this something you are will to try to fix?

@heath-freenome heath-freenome added help wanted awaiting response and removed needs triage Initial label given, to be assigned correct labels and assigned labels Mar 1, 2024
@anya92
Copy link
Author

anya92 commented Mar 4, 2024

@heath-freenome Thank you for the response. I did notice that turning off omitExtraData resolves the issue, but in my project, it needs to be turned on. Unfortunately, I'm not very familiar with the codebase, so making a quick fix might be challenging for me.

@heath-freenome
Copy link
Member

@anya92 I started out not being very familiar with the codebase either. Most of the code you want to look at is in the Form class in @rjsf/core. Feel free to reach out if you have any questions. Thanks

@anya92
Copy link
Author

anya92 commented Mar 12, 2024

@heath-freenome I checked the changes in the package and I'm pretty sure my schema stopped working after updating retrieveSchema() in version 5.13.1 and this function started resolving references. In the version I'm currently using, $refs are not resolved.

But even if I manually got rid of $ref and my schema looks like this:

{
  "title": "Schema",
  "type": "object",
  "properties": {
    "array_of_objects": {
      "title": "Array of Objects",
      "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"
        ]
      }
    }
  }
}

The issue still exists (playground).

You may notice that the if...then section is nested inside array_of_objects. If I move it up, the form will work and the data will not be deleted (playground). But I think this should also work with the above schema because the conditional field is rendered correctly and the validation still throws an error.

Do you have any idea what is causing this behavior and where to fix it?

@heath-freenome
Copy link
Member

@anya92 The issue is in the omitExtraData code that is currently in Form. Interestingly someone is working on a PR to pull that code down into the utils library (#4139), maybe you can work with them to see if there is a fix that can be made during the extraction.

@helen-m-lin
Copy link
Contributor

Hi @heath-freenome, I'm also having issues with omitExtraData during onSubmit, though not entirely sure if it's the same thing @anya92 is describing.
What is the expected behavior? I assumed that it should first omit any extra data in the formData, and then validate the resulting newFormData. Currently I don't think newFormData is being used for validation here.

newFormData = this.getUsedFormData(newFormData, fieldNames);
}
if (noValidate || this.validateForm()) {

If needed, I am happy to help out to implement a fix.

@sahmurthy
Copy link

Has there been any update to fix this issue yet?

@heath-freenome
Copy link
Member

@helen-m-lin How goes the fix we discussed?

@helen-m-lin
Copy link
Contributor

Sorry, I haven't had the chance to work on it! Thank you for the reminder. I will work on the fix this later this week.

@anya92
Copy link
Author

anya92 commented Jul 9, 2024

Hi @helen-m-lin and @heath-freenome.

First of all, I would like to thank you for your work and recent PR to address this issue. However, I wanted to let you know that the problem at the playground still exists.

It seems that the problem is not related to liveOmit and omitExtraData as I initially thought. Instead, it seems to be more closely related to nested if...then conditions.

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.

4 participants