angular2-json-schema-form: What's wrong with form?
`{
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"Objects": {
"type": "array",
"items": {
"type": "object",
"properties": {
"object": {
"type": "object",
"properties": {
"objectId": {
"type": "string"
},
"attributes": {
"type": "array",
"items": {
"type": "object",
"properties": {
"attributeId": {
"type": "string"
},
"attrbuteName": {
"type": "string"
},
"value": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
},
"form": [
"name",
{
"key" :"Objects",
"items": [
{
"key":"Objects[].object",
"items": [
"objectId",
{
"key": "attributes",
"items": [
"attributes[].attributeId",
"attributes[].attrbuteName",
"attributes[].value"
]
}
]
}
]
}
]
}`
Why I don’t see “attributeId”, “attrbuteName” and “value”?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 22
The keyword is
htmlClass.The
schema: part is only about data types: string, number, required etc.The
layout: part is all about presentation, in HTML. What colour the field has, how wide is it, which HTML class has to be used/applied.So, the answer is, put it in the
layout: part.Just out of curiosity, is this a student assignment ?
Sorry about the error on schemaform.io, there is a small mistake in the payload, take this one:
You need to implement a couple of methods in your schema model, the one that controls the schema form.
Mine is like this:
You see the
onChangesspecified ? It is being called on every change.You may want to check of the attribute Id is set, fetch the object, and assign the name attribute accordingly.
Good luck!
By the way, do yourself a favour and clean up the schema, start with this:
That’s something you should probably handle outside of the schema form. Were I asked to do that task I would write a function to check if the data is valid. Then, I would create a function to fire an ajax request if the given data passes the data validity check function. Finally I would connect the JSON schema onchanges function to the ajax function.
I made this similar setup b/c I found your schema a bit confusing and preferred doing from scratch to ensure I understood the schema completely:
Looking back, I think the reason yours wasn’t working was that you weren’t referencing the parent objects array in the attributes items array.