Comments (5)
Hi @juicycleff !
Indeed, JSF does have two limitations around group-array fields ("type": "array"
).
First, currently, the group-array field only accepts a list of objects. (like in this demo, where each item is {full_name, birthdate, sex}
.
So, even a simpler JSON Schema like the following — an array of strings — would break in the JSF:
{
"type": "object",
"additionalProperties": false,
"properties": {
"hobbies": {
"items": {
"title": "Hobby name",
"type": "string"
},
"x-jsf-presentation": {
"inputType": "group-array",
"addFieldText": "Add new hoddy"
},
"title": "Hobbies",
"type": "array"
}
},
"required": ["hobbies"]
}
A workaround could be changing the structure to:
{
"type": "object",
"additionalProperties": false,
"properties": {
"hobbies": {
"items": {
"properties": {
"name": {
"title": "Hobby name",
"type": "string"
}
}
},
"x-jsf-presentation": {
"inputType": "group-array",
"addFieldText": "Add new hoddy"
},
"title": "Hobbies",
"type": "array"
}
},
"required": [
"hobbies"
]
}
I'm not saying this is the fix, I'm just saying this is a workaround, which I understand might not be ideal for you because the JSON structure would change
// Before (not supported)
{ "hoobies": ["read", "video games"]}`
// Now (workaround)
- { "hoobies": [ {name: "read"}, {name: "video games"} ] }
The other JSF limitation is that currently group-array
do not work inside fieldsets
(which is in your example with hobbies.indoor[]
. Let's look at the shortest JSON Schema snippet:
{
"title": "My Form",
"type": "object",
"properties": {
"hobbies": {
"title": "Hobbies of employee",
"type": "object",
"properties": {
"indoor": {
"type": "array",
"items": {
"properties": {
"name": {
"title": "Hobby name",
"type": "string"
}
}
}
}
}
}
}
}
This breaks to render in the Playground, because as the error says Objects are not valid as a React child (found: TypeError: innerFields.forEach is not a function). If you meant to render a collection of children, use an array instead.
— The error is not intuitive, but basically it fails to loop innerFields
(group arrays) inside fieldsets. :/
The good news is that this bug is on our internal backlog too. I don't have a timeline for you though. Hopefully by the end of the year.
I'm sorry for not giving the answer you are looking for. This was just a dump of analyses/explanations around this bug.
from json-schema-form.
Any plans for better errors with traces to where in the schema the problem originates from?
from json-schema-form.
@jguddas what do you mean? Can you give an example? For example, the example above, you can see the error and trace-it in the dev tools.
from json-schema-form.
@jguddas what do you mean? Can you give an example? For example, the example above, you can see the error and trace-it in the dev tools.
An AJV style error might look something like this:
- JSON Schema invalid TypeError: innerFields.forEach is not a function
+ JSON Schema invalid: data/properties/hobbies/items/type must be object
from json-schema-form.
I believe we are talking about different things: this is not an error with JSON Schema (it's valid!). It's a run-time error with the json-schema-form
internals that doesn't support (yet) the given JSON Schema structure.
We could leave a DX error, yes, saying that for now, it must be an object, but that's a different issue. I've created an issue dedicated to it: #29
Regarding timelines, we don't know yet as the team is currently busy with other projects. Probably still this year.
from json-schema-form.
Related Issues (17)
- Public roadmap HOT 1
- Github: Create templates for issues and PR
- Add support for $ref keyword HOT 1
- docs examples HOT 1
- Better error messages when given a non-supported JSON Schema
- Missing documentation for 'formValuesToJsonValues' HOT 4
- select inputType and number type HOT 1
- custom errorMessage by field name doesn't work. HOT 1
- Conditionals attributes are not removed after the condition is unmatched
- Working with react native HOT 1
- Add a default export HOT 1
- Custom Error Messages doesn't work in JSF Config HOT 3
- InitialValues Problem HOT 3
- Inquiry about Roadmap HOT 2
- Consider support `$ref` in jsonschema HOT 2
- handleValidation for nested conditions is not working HOT 1
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 json-schema-form.