Comments (9)
@codisfy We released 5.17.0 yesterday, so you should be able to try out the new uiSchema functionality now
from react-jsonschema-form.
@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.
from react-jsonschema-form.
from react-jsonschema-form.
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.
{
"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.
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.
from react-jsonschema-form.
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.
@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.
from react-jsonschema-form.
Related Issues (20)
- Null Fields on Material Ui 5 HOT 2
- findSchemaDefinition doesn't detect cyclic references HOT 7
- `@rjsf/mui` has issues with the dark theme HOT 4
- Support custom error messages from schema HOT 2
- Filenames have an ugly "</strong>" printed next to them. HOT 3
- make it compatible with native esm HOT 3
- Duplicate widgets when rending OpenAPI's discriminated unions
- Usage Example is missing Form import
- Widgets unusable under Antd v5 using a dark theme (wrong ConfigProvider context passed down) HOT 3
- How to figure out the changed `formData` object property from inside `onChange` callback? HOT 4
- Warning: React does not recognize the `errorSchema` and Invalid DOM property `autocomplete`. HOT 1
- DOCUMENTATION Issue: Wrong method signature? HOT 1
- Schema defines standalone checkbox as mandatory, but asterisk is not rendered. HOT 2
- I would like to make a default change to the look of all input fields HOT 5
- Adding required field in nested if/then/else not working correctly HOT 2
- FormData is not received based on schema properties HOT 1
- Select bug when multiple oneOf are nested HOT 2
- How can I cite this? HOT 6
- RJSF anyOf customization HOT 3
- Validation error when multiple $ref references point to a single definition HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-jsonschema-form.