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

[Nested Lists] ListType: reset list when no value is submitted, cast objects with nu… #3776

Open
wants to merge 2 commits into
base: nested-lists
Choose a base branch
from

Conversation

naptowncode
Copy link

@naptowncode naptowncode commented Dec 9, 2016

Description of changes

  1. Reset list when no value is submitted. This allows user to empty out a list.
  2. Cast objects with numeric keys to array. This works around an unchangeable setting in multer that causes submitted arrays of 22 items or more to be parsed as objects instead of arrays.

Related issues (if any)

Testing

  • Please confirm npm run test-all ran successfully.

…meric keys to array

// Reset the value when null or an empty string is provided
if (values === null || values === '') {
// Reset the value when no value or null or an empty string is provided
if (values === undefined || values === null || values === '') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a definite change in semantics, I think it would be better to leave the undefined case as-is…

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was cheating here to fix two bugs at once.

With the undefined case as it is there is no way to empty out the list. The last item will never be deleted because an empty list won't be submitted at all. TextArray, DateArray, and NumberArray all treat undefined the way I've done here.

if (!Array.isArray(values)) {
values = [values];
if (typeof values === 'object' && values[0] !== undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should use hasOwnProperty in this instance, although for this particular use case, I suppose array values should always be at least null? Not sure.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, hasOwnProperty is probably more correct. Thanks!

@JedWatson JedWatson changed the title ListType: reset list when no value is submitted, cast objects with nu… [Nested Lists] ListType: reset list when no value is submitted, cast objects with nu… Dec 22, 2016
@JedWatson JedWatson self-assigned this Dec 22, 2016
@stennie stennie added the bug label May 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants