Skip to content

destroyStrategy works only on siblings that are array of objects. It does not work on other siblings. #529

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

Closed
ghost opened this issue Aug 28, 2015 · 2 comments

Comments

@ghost
Copy link

ghost commented Aug 28, 2015

I have not been successful in getting the destroy strategy to work on any sibling properties or sibling objects. It only works on sibling array of objects. Please check this example:

http://jsfiddle.net/mutharasus/dp18a70b/

In here if you select the first drop down to "Option1" then select all the other drop down and save. Then go back and switch the first drop down to "Option2" and save you can see that only the very last array of objects is removed with the destroy strategy.

Posted the same as a question:
http://stackoverflow.com/q/32253453/4496838

@jbsaff
Copy link
Contributor

jbsaff commented Aug 29, 2015

I've answered on StackOverflow as well, so I'll post the same here to try to catch the maximum audience.

You're correct, it's not currently behaving the way that you expect when an individual field is removed from the view because of a condition.

Here's what's happening: under the "old" bundled decorators for ASF, each field-type decorator is rendered on the page within an outer tag. The contents of the appropriate field template are then processed and rendered. Condition logic applies to everything within the tag, but not to the tag itself. Normally, this would be fine, but the destroyStrategy logic was assigned to the $destroy event of the tag. The end result is that the $destroy event will never fire unless the entire tag would be removed from the DOM. This is why the model values in the array of objects are being cleaned up - the container is removed when the "model.propertyOne === 'option1'" condition fails, which cascades the $destroy event to each object in the array.

I think that this got overlooked with the creation and release of the new builder, because I raised the issue at the end of the PR for the feature (#371).

On the bright side, the new builder approach (which you can use by adding the bootstrap-decorator file from https://github.com/Textalk/angular-schema-form-bootstrap) doesn't have this issue. Instead, the destroyStrategy logic is applied via directive to the form fields because the tag is no longer used. Unless you have a need to stay with the old decorators at this time, I suggest grabbing the new ones and giving them a try.

Let us know how it goes!

@Anthropic
Copy link
Member

@jbsaff that's great to hear the new builder fixes the issue, wont be too much longer till we get it out in v1

Please re-open if you do not feel the question has been answered sufficiently.

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

4 participants