angular-schema-form: Provide more useful error than "Invalid type, expected array"
I get this error while the output is exactly how I expect it, the problem is that the form is invalid.
Form
form = {
"key": "data.answers",
"type": "array",
"items": [
{
"key": "data.answers[]",
"items": [
{
"key": "data.answers[].text",
"type": "text",
"title": "Question",
},
]
}
]
},
Schema
scope.schema = {
"type": "object",
"title": "Types",
"properties": {
"data": {
"type": "object",
"title": "data",
"properties": {
"answers": {
"type": "array",
"title":"Answers",
"default": [],
"items": {
"type": "object",
"title": "Answer",
"properties": {
"text": {
"title": "Answer",
"type": "text",
"required": true,
},
}
}
}
}
}
}
};
expected output
data = {answers: [{text: “answer1”}, {text: “answer2”}], correct: 1, question: “questioning?”}
Now the expected output is right but the form is invalid saying that it expected an array, anything Im missing here?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 32 (13 by maintainers)
Commits related to this issue
- Fix for #625 This doesn't remove the error it removes it when an array of strings or numbers is specified and fails validation by inserting null to force a value into the array. — committed to json-schema-form/angular-schema-form by Anthropic 7 years ago
- Fix for #625 This doesn't remove the error it removes it when an array of strings or numbers is specified and fails validation by inserting null to force a value into the array. — committed to daklaus/angular-schema-form by deleted user 5 years ago
- some info here too: https://github.com/json-schema-form/angular-schema-form/issues/625 . — committed to TACC/Core-Portal by deleted user 6 years ago
- some info here too: https://github.com/json-schema-form/angular-schema-form/issues/625 . — committed to TACC/Core-Portal by deleted user 6 years ago
I was able to get rid of the issue by not using :
angular-schema-form-bootstrap 0.2.0
, but instead use the one that is in the dist folder of this repository (when you use npm or bower)Bower sees alpha 3 of angular schema form bootstrap, not an alpha 4 so I use the actual git commit id to get the absolute latest. I’m not sure how to change the versions in the gist link, to use angular schema form bootstrap latest, but even this example should show the issue, if the latest version is used.
http://schemaform.io/examples/bootstrap-example.html#/d127f6b978d7dff299afe010e91c2ea8
@donalmurtagh I have a fix for that based on comments in #649, will get it out in alpha.3 this week, should have in dev branch in the next day or two I hope.
I’ve got the same issue, but with valid input . Here is my code :
and in my view :
Now if I fill in the two arrays with multiple text elements, I get the error message :
"Invalid type, expected array"
I’m not sure this should have been closed. While @upq had a typo in his schema, @toomuchdesign did not and had to use a workaround that changed the schema.
We have the following schema fragment:
This works fine with the old decorator but breaks with the new one giving the on-screen error described. We can’t easily use the workaround as the documents already created follow the schema above.