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

When removing object from array, left with null instead of complete removal at index #429

Open
avishaan opened this issue Aug 18, 2016 · 1 comment

Comments

@avishaan
Copy link
Contributor

When I remove something like the below:
pasted_image_8_18_16__12_31_am
it looks like it get's removed, but when I go back to the document I see it as a blank entry
pasted_image_8_18_16__12_33_am
when checking in the database, I see that null is left behind instead of the array element being removed
pasted_image_8_18_16__12_34_am

it really should remove the entire element of the array, not replace it with null

@avishaan
Copy link
Contributor Author

because this package depends on https://github.com/aldeed/meteor-simple-schema#validating-data I realized I could just delete those null values upon save with a simple one-liner as follows in the autoValue function

Layouts.attachSchema(new SimpleSchema({
  'orgID': {
    'type': String,
    'label': 'Unique Id',
    'max': 50,
  },
  'categoryIds': {
    'type': [String],
    'label': 'Category Ids the schema applies to',
  },
  'graphs': {
    type: [ChartSchema],
    'autoValue': function() {
      // remove the null in array on update https://github.com/orionjs/orion/issues/429
      return this.value.filter(value => value !== null);
    },
  },
}));

Although it seems this issue presents itself in the actual dependency, I thought it would be helpful to have a post here as well for future reference

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

No branches or pull requests

1 participant