Skip to content

DestroyStrategy option is not working properly #703

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
warmy1004 opened this issue May 24, 2016 · 7 comments
Closed

DestroyStrategy option is not working properly #703

warmy1004 opened this issue May 24, 2016 · 7 comments

Comments

@warmy1004
Copy link

warmy1004 commented May 24, 2016

Enhancement

In my case, three conditional questions (text, select, and radios-inline types) are showing and hiding based on the main question's value. Any previously entered input for these conditional questions should be removed or set to be empty when these conditional questions are removed. But, destroyStrategy for them is not working properly.

Expected behaviour

I expected the previously entered data for conditional questions will be removed (which is default) for text and radios-inline types and set to be empty for the select type when form elements are disappeared from the screen.

Actual behaviour

If valid data is entered, the data is always retained (it is not removed or set to be empty). However, if invalid data is entered, this invalid data is cleaned up (removed) when the form element is removed from the screen.
For valid data, $destroy event seems to be not calling properly.

Gist/Plunker/Demo

https://plnkr.co/edit/rYuk0YmBDN3k3sTJusAy?p=preview

Related issues

This is/maybe related to ...#689

@json-schema-form/angular-schema-form-lead

@warmy1004
Copy link
Author

For your information, here is version information which I am using in Plunker.
angularjs & angular-sanitize : v 1.4.3
schema-form : v 0.8.13
bootstrap-decorator.js : v 0.8.13 which is provided in the schema-form-v.0.8.13 folder
ObjectPath: v 1.2.1
tv4: v 1.0.17

@Anthropic
Copy link
Member

@warmy1004 thanks for the additional info, once the webpack/babel branch is stabilised we will be able to look at this.

@warmy1004
Copy link
Author

warmy1004 commented Jun 8, 2016

I want to share with you what I found for this issue.
I can't be fully sure, but I think this issue is caused by a mismatch between actual form's structure from a canonical form definition and a needed structure for angularjs's destroy event.
When the angularjs is broadcasting a destroy event (the current angularjs's code is this.$broadcast('$destroy'); ), this broadcast destroy event can't be caught properly by schema-form because 'this' doesn't have form information. Instead, this.$parent has form information, so if I change the above angularjs's destroy code to 'this.$parent.$broadcast('$destroy');' destroyStrategy is working for me.
Hopefully, it will help you to solve this issue.

@Anthropic
Copy link
Member

@warmy1004 thanks for the info, I appreciate your follow up, once the webpack/babel branch is merged to dev, hopefully someone can do a PR to correct the behaviour or add a test case for me to fix against.

@Anthropic Anthropic added this to the 1.0.0 milestone Jun 9, 2016
@Anthropic Anthropic self-assigned this Feb 27, 2017
@Anthropic
Copy link
Member

@warmy1004 how does this one look on the latest dist folder files in dev branch? Are you able to confirm it is working again after all the changes I made to fix destroy behaviour?

@warmy1004
Copy link
Author

@Anthropic I retested it and this is fixed in the alpha 4 version. Thank you.

@Anthropic
Copy link
Member

Woo hoooo!

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