Expand my Community achievements bar.

SOLVED

Remove instance button works but does not clean data.

Avatar

Former Community Member

I have very simple code. On click of the button Add you can add unlimited # of instances. On click of the button remove, you remove instance. Works fine, removes all instances, but when you click Add button again, it adds first instance with the data you have entered before. It does not clean data from the first instance. Does anyone have any suggestion please. How do you clean data from the last instance before removeing it?

some code

.

.

.

.

 

}

else

{

Sub1.Sub2._Sub3.removeInstance(this.parent.parent.parent.parent.index);

 

}

 

xfa.layout.relayout();

1 Accepted Solution

Avatar

Correct answer by
Level 10

If you observe the code I sent you earlier, I was passing the index of the subform that needs to be cleared.

But there is one issue with the above code: instead of Square brackets, I had placed regular bracket.

var intIndex = this.parent.parent.parent.parent.index; //identify the index of the subform instance you want to delete data from.

xfa.host.resetData("Sub1.Sub2.Sub3[" + intIndex + "]");

Thanks

Srini

View solution in original post

4 Replies

Avatar

Level 10

The removeInstance should remove the data in all the fields in the Subform along with deleting the Subform from the form.

Probably try commenting the xfa.layout.relayout() line in the code.

To delete the data in all the fields within the subform, you can use:

     xfa.host.resetData("Sub1.Sub2.Sub3(" + this.parent.parent.parent.parent.index + ")");

If you still have issues, probably sharing the document might help.

Thanks

Srini

Message was edited by: Srini Dhulipalla

Avatar

Former Community Member

Thanks Srini. The problem is that the code above will remove data for all added instances. If I add 5 instances, with the code above, if I want to delete instance 4 and delete all that for instance 4, it will wipe out all data for all instances above, not just the instance 4.

I need a code that will clean all the fields for the individual instance before removing it. resetData() does not work as it cleans all instances.

Avatar

Correct answer by
Level 10

If you observe the code I sent you earlier, I was passing the index of the subform that needs to be cleared.

But there is one issue with the above code: instead of Square brackets, I had placed regular bracket.

var intIndex = this.parent.parent.parent.parent.index; //identify the index of the subform instance you want to delete data from.

xfa.host.resetData("Sub1.Sub2.Sub3[" + intIndex + "]");

Thanks

Srini

Avatar

Former Community Member

Thanks Srini. It works now. I used your code and make some additional changes to the subforms I was referencing.