json-schema-form / angular-schema-form

Generate forms from a JSON schema, with AngularJS!
https://json-schema-form.github.io/angular-schema-form
MIT License
2.47k stars 653 forks source link

Specify 'destroyStrategy' for array item removal #916

Open andrei-dracea opened 7 years ago

andrei-dracea commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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?