Skip to content
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

Array of objects data entry not working with liveOmit #1396

Closed
epicfaace opened this issue Aug 11, 2019 · 6 comments · Fixed by #1419
Closed

Array of objects data entry not working with liveOmit #1396

epicfaace opened this issue Aug 11, 2019 · 6 comments · Fixed by #1419

Comments

@epicfaace
Copy link
Member

Description

Array of objects data entry not working with liveOmit.

Steps to Reproduce

  1. Go to this playground link
  2. Type in a value for "name".

Expected behavior

The form data should be

[{name: "asdasd"}]

Actual behavior

The form data is {} -- somehow liveOmit is not adding in the data properly.

image

Version

1.7.0+ (latest version from master)

This seems to be a regression added by PR #1371 .

PR #1371 demo

PR #1372 demo (right before #1371)

@Tonexus
Copy link
Contributor

Tonexus commented Aug 13, 2019

It looks like the lodash _pick call here is causing the issue

https://github.com/mozilla-services/react-jsonschema-form/blob/20ff3b97a18c061e08bc157fd3851cf4ba7101c6/src/components/Form.js#L136-L143

According to the lodash docs, _pick will always return an object, which will mess up validation if the root type of the schema is an array.

@epicfaace
Copy link
Member Author

@Tonexus hmm, thanks... Do you have a way in mind that might fix it?

@Tonexus
Copy link
Contributor

Tonexus commented Aug 14, 2019

I created a PR that fixes part of the issue, but I found a second problem. The current usage of _pick doesn't seem able to preserve an empty object (or an empty array) inside of an array, so your specific example will still be bugged, as the objects containing the text fields will be immediately removed. I don't have time to look more in depth right now, but a workaround would be to have some default value for the text field and otherwise making sure that the object is never empty.

@Tonexus
Copy link
Contributor

Tonexus commented Aug 16, 2019

@epicfaace Ok, it looks like there is only one case of nesting that does get preserved by omitExtraData. When there is an empty object inside of an object (compared to empty array in object, empty object in array, and empty array in array), _pick still removes the inside object, but it looks like it gets readded in getDefaultFormState in utils.js.

Should the same be happening for arrays? My main concern is that once _pick is called, you lose the array, so you don't know how many array elements you need to build again, so you would have to propagate that info. The alternative would be to do something else (or in addition) when _pick is called.

@epicfaace
Copy link
Member Author

It's also broken without dependencies: playground link

@MatinF
Copy link

MatinF commented Aug 21, 2019

We're seeing this issue as well in our form with the latest commit.

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