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

Delete key from path #562

Open
onlymejosh opened this issue Nov 17, 2020 · 1 comment
Open

Delete key from path #562

onlymejosh opened this issue Nov 17, 2020 · 1 comment

Comments

@onlymejosh
Copy link

onlymejosh commented Nov 17, 2020

Hey there I am looking for some guidance on how to handle deleting of keys from a changeset object.
I am working on a complex form which did have lots of nested arrays. I am trying out flattening the array to track the fields better. This definitely works better, but I cant work out how to delete the whole key / value and get the changes to be tracked.

This is what I have

{
  metadata: {
    fields: ['name','lastName','age']
    relatedFields: [
        { id: 1, name: 'foo', value: 'bar'}
    ]
}

Which becomes

{
  metadata: {
    'fields[0]': 'name',
    'fields[1]': 'lastName',
    'fields[2]': 'age',
    relatedFields[0].id: 1,
    relatedFields[0].name: 'foo'
    relatedFields[0].value: 'bar',
  }

This makes tracking much easier.

My question. How would I delete 'fields[1]': I tried delete changeset.data['fields[1]'] to no avail

@snewcomer
Copy link
Collaborator

👋 Thx for the issue! A few questions...

  1. Is this flattened structure passed to the Changeset contructor?
  2. How come you are trying to delete the fields and mutate the underlying model? Is going through the changeset a possibility? e.g. changeset.set('metadata.fields[0]', null);

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

2 participants