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

Specify 'destroyStrategy' for array item removal #916

Open
andrei-dracea opened this issue Jul 18, 2017 · 2 comments
Open

Specify 'destroyStrategy' for array item removal #916

andrei-dracea opened this issue Jul 18, 2017 · 2 comments

Comments

@andrei-dracea
Copy link

andrei-dracea commented Jul 18, 2017

Enhancement

As a developer, I would like to be able to set a destroyStrategy for array form types, so that when I remove an item, I can have it empty instead of destroyed (to keep track of changes).

Expected behaviour

I expected destroyStrategy to work on array form types.

Actual behaviour

It actually does not work like that. Nor does it provide any means of intercepting the remove item event.

Gist/Plunker/Demo

You can check in the Array section of the demo.
http://schemaform.io/examples/bootstrap-example.html

Thanks!

@Anthropic
Copy link
Member

Hi @andrei-dracea when I click remove on the array item the comments array is showing as an empty array, what were you hoping it would show?

Are you wanting the array item itself to remain? That could be achieved with a button hiding the item rather than removing it, the default array buttons delete the array item so there is no item for ASF to act upon. If the array included a section with a condition you could show and hide items within the array by setting a property not in the schema.

I would expect a better method to keep track of removed items would be to have your own button that moves the item to another array.

@andrei-dracea
Copy link
Author

andrei-dracea commented Jul 19, 2017

Further explaining

So, when you click remove, I was hoping there was a way I could specify something like destroyStrategy: "empty", so that I could have the order of the items remain the same, when I already have some data into the form.
I still need the form item to disappear, but the array item to remain (see bellow).

For the comments array example, starting from this model:

  "comments": [
    {
      "spam": false,
      "name": "ken",
      "email": "ken@gmale.com"
    },
    {
      "spam": false,
      "name": "barbie",
      "email": "barbie@girl.com"
    }
  ]
}

after removing the first item, I would like to be left with:

{
  "comments": [
    {
      "spam": "",
      "name": "",
      "email": ""
    },
    {
      "spam": false,
      "name": "barbie",
      "email": "barbie@girl.com"
    }
  ]
}

Regarding your suggestions

So what you are saying is that I should disable the default remove button and generate my own, with custom actions? Is there a way to override the default action?

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

2 participants