Skip to content

Why are array fields allowed to contain undefined, but other fields aren't? #120

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

Closed
pikajude opened this issue Oct 13, 2014 · 4 comments
Closed

Comments

@pikajude
Copy link

Probably the easiest way to see this is to check the "Kitchen Sink" example and see "dislike": [null] at the bottom. null is neither a valid string value nor undefined. This trips up the jsonschema library which I'm using in conjunction with this one, because it doesn't check for nulls.

I looked through the code but wasn't able to figure it out. I know that arrays get an empty item added to them if they don't have a default value, but I don't know why it ends up in the output rather than just getting filtered out, like other invalid/non-present attributes do.

@davidlgj
Copy link
Contributor

Yes, this is a bit of an ugly problem that I haven't solved yet, basically I add null to the list so that the ng-repeat that repeats over the list can create one empty form element. So it's basically an artifact of a poor solution to a problem.

The real solution I guess would be to handle the extra empty form outside of the ng-repeat and append to the list when something is written in the subform. I'm marking this as a bug.

@philippbosch
Copy link

I also ran into that problem. In my case it would be sufficient if I could disable the extra empty form and make it only show up when the user clicks the add button. Is there a way to achieve this behavior?

@davidlgj
Copy link
Contributor

davidlgj commented Jan 7, 2015

It's undocumented... but you can use the form option startEmpty, if its set to true (in the array form definition it starts empty) the array start empty with just an add button.

See https://github.com/Textalk/angular-schema-form/blob/master/src/directives/array.js#L136

@nekto0n
Copy link

nekto0n commented Jan 7, 2015

Wow, thanks, @davidlgj. This option should be definitely documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants