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

Nested dependencies not updated correctly #3450

Open
1 task done
sunkeysun opened this issue Feb 21, 2023 · 17 comments
Open
1 task done

Nested dependencies not updated correctly #3450

sunkeysun opened this issue Feb 21, 2023 · 17 comments
Labels
any-one-all-of Related to fixing anyOf, oneOf or allOf bug help wanted utils Related to @rjsf/utils

Comments

@sunkeysun
Copy link

sunkeysun commented Feb 21, 2023

Prerequisites

What theme are you using?

core

What is your question?

Playground

https://codesandbox.io/s/black-forest-bgkbeo?file=/src/App.js
As example, conditinal schema property value not update as expected.
when "animal" change to "Cat", "food" should be "meat".

schema.json

{
  "type": "object",
  "properties": {
    "animal": {
      "enum": ["Cat", "Fish"],
      "default": "Cat"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "animal": {
            "const": "Cat"
          }
        }
      },
      "then": {
        "properties": {
          "food": {
            "type": "string",
            "enum": ["meat", "grass", "fish"],
            "default": "meat"
          }
        },
        "required": ["food"]
      }
    },
    {
      "if": {
        "properties": {
          "animal": {
            "const": "Fish"
          }
        }
      },
      "then": {
        "properties": {
          "food": {
            "type": "string",
            "enum": ["insect", "worms"],
            "default": "insect"
          },
          "water": {
            "type": "string",
            "enum": ["lake", "sea"],
            "default": "lake"
          }
        },
        "required": ["food", "water"]
      }
    },
    {
      "required": ["animal"]
    }
  ]
}

image

@sunkeysun sunkeysun added needs triage Initial label given, to be assigned correct labels and assigned question labels Feb 21, 2023
@heath-freenome
Copy link
Member

heath-freenome commented Feb 24, 2023

@sunkeysun We don't have great support for if/then/else in allOf. It is definitely a bug in how we populate form data. Are you willing to try to create a fix?

@heath-freenome heath-freenome added bug any-one-all-of Related to fixing anyOf, oneOf or allOf utils Related to @rjsf/utils help wanted and removed needs triage Initial label given, to be assigned correct labels and assigned question labels Feb 24, 2023
@sarpere
Copy link
Contributor

sarpere commented Mar 14, 2023

@heath-freenome I can take care of the bug, if nobody working on the issue.

@heath-freenome
Copy link
Member

@sarpere That would be great!

@furkan-akinci
Copy link

any updates?

@sunkeysun
Copy link
Author

@heath-freenome I can take care of the bug, if nobody working on the issue.

any updates?

@heath-freenome
Copy link
Member

@sunkeysun I am awaiting a PR from @sarpere

@sarpere
Copy link
Contributor

sarpere commented Apr 14, 2023

@heath-freenome I could not have a time to fix it. if someone can to fix it, It would be better.

@mahendra790
Copy link

@heath-freenome Any updates?

I can work on it

@heath-freenome
Copy link
Member

@mahendra790 Nothing has happened, so please do feel free to work on a fix

@mahendra790
Copy link

@heath-freenome do we have any potential solution or a way in which we can fix this? Because from my initial understanding I think we somehow have to remove or add properties to form data when a field changes then the defaults can be applied

@mahendra790
Copy link

mahendra790 commented Feb 23, 2024

@heath-freenome There are multiple problems I am facing with allOf with if then else

  1. Defaults are not working correctly it just works for the first time, then the correct default is not set for the field.
  2. It also does not sanitize the form data to remove the fields which are not present in new schema.
  3. It also does not handle the case where the current value in the field is not valid according to new schema I think it should first see if the current value is also valid in new schema, if yes fine otherwise try to use default if present otherwise just reset it.

If I call sanitizeFormData on schema changes then 1 and 2 works fine if we have defaults set for fields otherwise if there is common field incorrect value is not cleared https://github.com/mahendra790/react-jsonschema-form/pull/1/files

I am using this syntax in one of my project and need to get this fixed, can you please guide me how we should approach this problem, may be if we can jump on a call it would be very helpful. I am ready to fix this

@mahendra790
Copy link

@heath-freenome can you please check once?

@heath-freenome
Copy link
Member

@mahendra790 Sorry, I missed your request for a call. I am free March 8th from 3-5pm Pacific Time. If that works, we can jump on discord.

@mahendra790
Copy link

@mahendra790 Sorry, I missed your request for a call. I am free March 8th from 3-5pm Pacific Time. If that works, we can jump on discord.

@heath-freenome sorry, I was busy in some work, can we connect in this week?

@heath-freenome
Copy link
Member

@mahendra790 You are welcome to join the weekly meeting as well. We have the next one tomorrow at 3pm Eastern and noon Pacific

@mahendra790
Copy link

@mahendra790 You are welcome to join the weekly meeting as well. We have the next one tomorrow at 3pm Eastern and noon Pacific

@heath-freenome how can I get the link for the meeting?

@heath-freenome
Copy link
Member

It's in the pinned issue on the top of the issues page

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 help wanted utils Related to @rjsf/utils
Projects
None yet
Development

No branches or pull requests

5 participants