-
Notifications
You must be signed in to change notification settings - Fork 647
Provide more useful error than "Invalid type, expected array" #625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Same problem here. The validation error (Invalid type, expected array) appears when adding a second item into an array field. It seems to be a problem related to angular-schema-form-bootstrap. I have no troubles when using the old decorators included in ASF folder. This is my current setup:
I'm going to investigate on this in the next days and set up a plunkr if needed. |
@upq back to your example: are you sure about setting "type" properties to "text"? I suppose the correct type for your text items in Schema declaration should be "string" ;-) Follow the schema in the official examples:
|
Meanwhile I found an acceptable solution. I had the validation issue when trying to get an array of textarea-strings:
I was able to overtake the validation issue by setting the field up as an array of objects as described in the demo:
|
@toomuchdesign changing the type to string actually worked! its always something dead silly and simple that is missing.. |
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: "features" : {
"type" : "array",
"title" : "Features",
"items" : {
"type" : "string",
"required" :true
}
} 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. |
I have recently had the same issue but it was due to the data returned from the server changing null to empty string on a field, but rather than show a useful error, I got the above. Suffice to say it took some time to determine that the returned string was failing the array item as it was defined as being an integer value. I think we need to look at improving the feedback on this one. |
@Anthropic, I confirm your issue: empty strings values returned by the server breaking the validation. I ended up with iterating the returned data object and removing empty values before sending data to the server. |
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 : |
This is very strange, since if I set the model to :
However, If I do the same thing manually, the error appears. |
@edi9999 it isn't strange at all it matches exactly what was described in the thread above your comments. If you set it to empty to start with it errors. You cannot reset it, too late. This needs work to fix. |
I was able to get rid of the issue by not using : |
@edi9999 thanks for the info :) |
I also get this issue when I use |
@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. |
@Anthropic Great, I'll try that out alpha3 as soon as it's available. It would really be appreciated if you could mention in the release notes of alpha3 which version of the bootstrap decorator it should be used with. |
Hi, Id be interested to see your fix for this in alpha 3 also Anthropic. Is a patch already merged for the fix? |
@mark007 due to family emergency I haven't gotten alpha 3 out yet, I am hoping to get something out this weekend if everything lines up for me. |
Thanks Anthropic. In general is there a list of features in lets say json schema draft 4, that asf currently does / doesn't support? I couldn't see any particular list on the github pages themselves, ie whether theres support for validation of things like string types with particular formats, like ipv4 etc. From searching the code I assume things like that aren't in there currently, but just wanted to know was there a place to go to see what is / isn't in there. Its a great project, we would love to contribute to it when we get more familiar with its workings. |
Can I just confirm guys, that this issue, is different to this other one ( #750 ) one that has had fixes pushed up for it. Thanks very much. |
@mark007 It is different, I believe, but I do believe that this issue is fixed by either alpha 3 already or 4 in dev branch. I can't change the error message which comes from tv4, but at least now when you change the value it should remove the error and it should display only when it is accurate. |
Thanks Anthropic. Thats why I wasn't sure, in my bower.json I'm pulling down todays latest push for angular-schema-form-bootstrap, but on page load, under my array field I still see the error appearing, even after I fill in the individual array items to make them valid. Do you think I should put together an example or is it easy to also see this on your end. I'm using angular 1.6.4. This is a snippet of what I have in my schema incase you wanted to try. "ntp_external_servers": { If I load the page with actual data set for this field its fine, its only when I load the page where the user has to initially give data, it doesn't like that this field has nothing set for it yet. |
@mark007 If you use the example and make a gist with a schema and form definition I can load that on the latest version locally and debug. Which versions is bower pulling down? ps. back on tomorrow |
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 |
I still see the issue on alpha 3 when using array of strings |
@EtiAggarwal @mark007 to be clearer, the main thing I fixed was that once the error appeared you couldn't get rid of it, to fix this entire issue I have updated ASF just now to put in an empty string instead of null, it will be in the next alpha update or you can try the version in the dev branch. |
Thanks Anthropic, I can't seem to pick it up yet using the schema form bootstrap bundled min file. I guess its not merged yet, I will pick it up once its there. Thanks again. |
@mark007 it should be, what version of the file are you using, what's the version headers say? |
This is from the header of the bundled asf bootstrap file, looks like it was just built yesterday. /*! I still have the issue if I don't set all of the array fields to [] before passing to the form, the error is appearing for me. Whats the easiest way to reproduce this for you. gist doesn't seem to have the ability to let me pick the exact version of the ASF bootstrap. I wonder did the bundled bootstrap one get the fix merged in from the other repo. |
@mark007 plunkers are the best method @warmy1004 has made some great ones, he bothered to put in multiple versions so you can compare, try this one and modify how you like the one thing I would ask is that you make sure the schema and form definition are json compatible and not js or I have to go and add quote on all the properties if I want to test it in my local test instance :) |
Hi I took a liberty to tweak this example and to show there still is issue going here here Invalid type, expected array. To reproduce you just need to add new element. Also if any of child elements pass validation and you remove last one, it works properly |
It seems like the parent form isn't updated when sub item changes. If I add a requirement on a string in items array like maxLength: 5 it gets even more weirder |
@Tarjei400 that's using alpha.2 the current one is alpha.4 and dev branch is a little ahead of that already. |
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.
I get this error while the output is exactly how I expect it, the problem is that the form is invalid.
Form
Schema
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?
The text was updated successfully, but these errors were encountered: