Coder Social home page Coder Social logo

Comments (9)

nickgros avatar nickgros commented on May 17, 2024 1

@codisfy We released 5.17.0 yesterday, so you should be able to try out the new uiSchema functionality now

from react-jsonschema-form.

nickgros avatar nickgros commented on May 17, 2024

@harrydoddnoble RJSF has no way of knowing that you discriminator on each oneOf field using that constant value. One change you could make is to give each of your oneOf schemas a title, and then use the UI Schema to hide the field that you don't want to show.

Here's a playground example.

from react-jsonschema-form.

harrydoddnoble avatar harrydoddnoble commented on May 17, 2024

from react-jsonschema-form.

harrydoddnoble avatar harrydoddnoble commented on May 17, 2024

Aah I'm still struggling a bit with this one - with the given solution you lose the title of the ski/swim question. I'm also working with an existing JSON schema and I'm not sure I understand how to get this to work properly.. any help/ideas would be very welcome!

In the example below you are asked if you insure the property and there is some logic after that - it generally works from a logic point of view but the UI is quite confusing so I'm not sure what I need to change to correct it.
image

{
  "properties": {
    "insurance": {
      "baspiRef": "A8",
      "ta6Ref": "6",
      "title": "Insurance",
      "type": "object",
      "baspiRequired": [
        "isInsured"
      ],
      "ta6Required": [
        "isInsured"
      ],
      "properties": {
        "isInsured": {
          "baspiRef": "A8.1",
          "rdsRef": "Insurance/isInsured=no|yes|true|false",
          "ta6Ref": "6.1",
          "piqRef": "A8.2",
          "title": "Do you insure the property?",
          "type": "string",
          "enum": [
            "Yes",
            "No"
          ]
        }
      },
      "discriminator": {
        "propertyName": "isInsured"
      },
      "oneOf": [
        {
          "properties": {
            "isInsured": {
              "enum": [
                "No"
              ]
            },
            "details": {
              "baspiRef": "A8.1.1",
              "ta6Ref": "6.2",
              "title": "Why not?",
              "type": "string",
              "minLength": 1
            },
            "landlordInsuresIfFlat": {
              "baspiRef": "A8.1.2",
              "ta6Ref": "6.3",
              "title": "If the property is a flat, does the landlord insure the building?",
              "type": "string",
              "enum": [
                "Yes",
                "No",
                "Not applicable"
              ]
            }
          },
          "baspiRequired": [
            "details",
            "landlordInsuresIfFlat"
          ],
          "ta6Required": [
            "details",
            "landlordInsuresIfFlat"
          ]
        },
        {
          "properties": {
            "isInsured": {
              "enum": [
                "Yes"
              ]
            },
            "difficultiesObtainingInsurance": {
              "baspiRef": "A8.1.2.1",
              "rdsRef": "Insurance/Flags,Insurance/refusalReason=?",
              "ta6Ref": "6.4",
              "piqRef": "A8.1",
              "title": "Have you had any difficulty obtaining competitively priced building insurance due to the structure or location of the property or had insurance refused?",
              "type": "object",
              "baspiRequired": [
                "abnormalRiseInPremiums",
                "subjectToHighExcesses",
                "subjectToUnusualConditions",
                "refused"
              ],
              "ta6Required": [
                "abnormalRiseInPremiums",
                "subjectToHighExcesses",
                "subjectToUnusualConditions",
                "refused"
              ],
              "properties": {
                "abnormalRiseInPremiums": {
                  "baspiRef": "A8.1.2.1.1",
                  "ta6Ref": "6.4a",
                  "piqRef": "A8.1a",
                  "title": "Subject to abnormal rise in premiums?",
                  "type": "object",
                  "properties": {
                    "yesNo": {
                      "baspiRef": "A8.1.2.1.1.1",
                      "ta6Ref": "6.4a1",
                      "piqRef": "A8.1a1",
                      "type": "string",
                      "title": "",
                      "enum": [
                        "Yes",
                        "No"
                      ]
                    }
                  },
                  "baspiRequired": [
                    "yesNo"
                  ],
                  "ta6Required": [
                    "yesNo"
                  ],
                  "discriminator": {
                    "propertyName": "yesNo"
                  },
                  "oneOf": [
                    {
                      "properties": {
                        "yesNo": {
                          "enum": [
                            "No"
                          ]
                        }
                      }
                    },
                    {
                      "properties": {
                        "yesNo": {
                          "enum": [
                            "Yes"
                          ]
                        },
                        "details": {
                          "baspiRef": "A8.1.2.1.1.2",
                          "ta6Ref": "6.4.2",
                          "piqRef": "A8.1a1.1",
                          "title": "Provide details",
                          "type": "string",
                          "minLength": 1
                        }
                      },
                      "baspiRequired": [
                        "details"
                      ],
                      "ta6Required": [
                        "details"
                      ]
                    }
                  ]
                },
                "subjectToHighExcesses": {
                  "baspiRef": "A8.1.2.1.2",
                  "ta6Ref": "6.4b",
                  "piqRef": "A8.1b",
                  "title": "Subject to high excesses?",
                  "type": "object",
                  "properties": {
                    "yesNo": {
                      "baspiRef": "A8.1.2.1.2.1",
                      "ta6Ref": "6.4b1",
                      "piqRef": "A8.1b1",
                      "type": "string",
                      "title": "",
                      "enum": [
                        "Yes",
                        "No"
                      ]
                    }
                  },
                  "baspiRequired": [
                    "yesNo"
                  ],
                  "ta6Required": [
                    "yesNo"
                  ],
                  "discriminator": {
                    "propertyName": "yesNo"
                  },
                  "oneOf": [
                    {
                      "properties": {
                        "yesNo": {
                          "enum": [
                            "No"
                          ]
                        }
                      }
                    },
                    {
                      "properties": {
                        "yesNo": {
                          "enum": [
                            "Yes"
                          ]
                        },
                        "details": {
                          "baspiRef": "A8.1.2.1.2.2",
                          "ta6Ref": "6.4.2",
                          "piqRef": "A8.1b2",
                          "title": "Provide details",
                          "type": "string",
                          "minLength": 1
                        }
                      },
                      "baspiRequired": [
                        "details"
                      ],
                      "ta6Required": [
                        "details"
                      ]
                    }
                  ]
                },
                "subjectToUnusualConditions": {
                  "baspiRef": "A8.1.2.1.3",
                  "ta6Ref": "6.4c",
                  "piqRef": "A8.1c",
                  "title": "Subject to unusual conditions?",
                  "type": "object",
                  "properties": {
                    "yesNo": {
                      "baspiRef": "A8.1.2.1.3.1",
                      "ta6Ref": "6.4c1",
                      "piqRef": "A8.1c1",
                      "type": "string",
                      "title": "",
                      "enum": [
                        "Yes",
                        "No"
                      ]
                    }
                  },
                  "baspiRequired": [
                    "yesNo"
                  ],
                  "ta6Required": [
                    "yesNo"
                  ],
                  "discriminator": {
                    "propertyName": "yesNo"
                  },
                  "oneOf": [
                    {
                      "properties": {
                        "yesNo": {
                          "enum": [
                            "No"
                          ]
                        }
                      }
                    },
                    {
                      "properties": {
                        "yesNo": {
                          "enum": [
                            "Yes"
                          ]
                        },
                        "details": {
                          "baspiRef": "A8.1.2.1.3.2",
                          "ta6Ref": "6.4.2",
                          "piqRef": "A8.1c2",
                          "title": "Provide details",
                          "type": "string",
                          "minLength": 1
                        }
                      },
                      "baspiRequired": [
                        "details"
                      ],
                      "ta6Required": [
                        "details"
                      ]
                    }
                  ]
                },
                "refused": {
                  "baspiRef": "A8.1.2.1.4",
                  "ta6Ref": "6.4d",
                  "piqRef": "A8.1d",
                  "title": "Refused?",
                  "type": "object",
                  "properties": {
                    "yesNo": {
                      "baspiRef": "A8.1.2.1.4.1",
                      "ta6Ref": "6.4d1",
                      "piqRef": "A8.1d1",
                      "type": "string",
                      "title": "",
                      "enum": [
                        "Yes",
                        "No"
                      ]
                    }
                  },
                  "baspiRequired": [
                    "yesNo"
                  ],
                  "ta6Required": [
                    "yesNo"
                  ],
                  "discriminator": {
                    "propertyName": "yesNo"
                  },
                  "oneOf": [
                    {
                      "properties": {
                        "yesNo": {
                          "enum": [
                            "No"
                          ]
                        }
                      }
                    },
                    {
                      "properties": {
                        "yesNo": {
                          "enum": [
                            "Yes"
                          ]
                        },
                        "details": {
                          "baspiRef": "A8.1.2.1.4.2",
                          "ta6Ref": "6.4.2",
                          "piqRef": "A8.1d2",
                          "title": "Provide details",
                          "type": "string",
                          "minLength": 1
                        }
                      },
                      "baspiRequired": [
                        "details"
                      ],
                      "ta6Required": [
                        "details"
                      ]
                    }
                  ]
                }
              }
            },
            "insuranceClaims": {
              "baspiRef": "A8.2",
              "rdsRef": "Insurance/Claims",
              "ta6Ref": "6.5",
              "title": "Have you ever made a claim against your building insurance in relation to the property?",
              "type": "object",
              "properties": {
                "yesNo": {
                  "baspiRef": "A8.2.1",
                  "ta6Ref": "6.5.1",
                  "type": "string",
                  "title": "",
                  "enum": [
                    "Yes",
                    "No"
                  ]
                }
              },
              "baspiRequired": [
                "yesNo"
              ],
              "ta6Required": [
                "yesNo"
              ],
              "discriminator": {
                "propertyName": "yesNo"
              },
              "oneOf": [
                {
                  "properties": {
                    "yesNo": {
                      "enum": [
                        "No"
                      ]
                    }
                  }
                },
                {
                  "properties": {
                    "yesNo": {
                      "enum": [
                        "Yes"
                      ]
                    },
                    "details": {
                      "baspiRef": "A8.2.1",
                      "ta6Ref": "6.5.2",
                      "title": "Provide details",
                      "type": "string",
                      "minLength": 1
                    }
                  },
                  "baspiRequired": [
                    "details"
                  ],
                  "ta6Required": [
                    "details"
                  ]
                }
              ]
            }
          },
          "baspiRequired": [
            "difficultiesObtainingInsurance",
            "insuranceClaims"
          ],
          "ta6Required": [
            "difficultiesObtainingInsurance",
            "insuranceClaims"
          ]
        }
      ]
    }
  }
}

from react-jsonschema-form.

nickgros avatar nickgros commented on May 17, 2024

You might be able to accomplish what you want with the uiSchema when we release a new version of RJSF that includes #4055

I spent a few minutes looking at your schema and was a bit overwhelmed. What you are trying to do is really best served by conditional logic in schemas. You said you can't use if/then/else, but could you use dependencies? This is another tool that you can use to implement conditional logic in your JSON Schema.

from react-jsonschema-form.

harrydoddnoble avatar harrydoddnoble commented on May 17, 2024

from react-jsonschema-form.

codisfy avatar codisfy commented on May 17, 2024

You might be able to accomplish what you want with the uiSchema when we release a new version of RJSF that includes #4055

@nickgros Do you know when will the next release be? I pulled a lot of hair today finally to realize that anyOf/oneOf on UISchema needed some updates and hasn't made to the release.

from react-jsonschema-form.

nickgros avatar nickgros commented on May 17, 2024

@harrydoddnoble now that #4055 was added to 5.17.0, are you able to use the uiSchema to achieve your desired behavior?

from react-jsonschema-form.

harrydoddnoble avatar harrydoddnoble commented on May 17, 2024

from react-jsonschema-form.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.