I have made a form that has an add button and remove button in a subform. Currently when the remove button is clicked on in any instance it removes the first instance. What is required to have the remove button remove the subform it sits within?
Solved! Go to Solution.
Views
Replies
Total Likes
Okay,
In the hierarchy check the relative path from the remove button to the ontreatment subform. If, for example, the remove button is in another subform, you would need to take this into account when determining the index of the repeatable ontreatment subform:
_ontreatment.removeInstance(this.parent.parent.index);
Each "parent" refers to the container or subform.
Hope that helps,
Niall
Views
Replies
Total Likes
The instance reference this.parent.index. For example,
_detail.removeInstance(this.parent.index);
Steve
Hi,
The addInstance() has a parameter of 1/0 or true/false, which relates to whether the new instance will be merged with the data model. Most offten you will use 1 or true.
However when it comes removeInstance(), the parameter refers to the specific instance you want to remove using the zero-based numbering system of the instances.
If the removeInstance() button is in the row.subform, then the following will work:
// _ is shorthand for instanceManager
_Subform1.removeInstance(this.parent.index);
this.parent.index will return the instance of the subform that contains the button.
Niall
Views
Replies
Total Likes
Hi,
Thanks for that. I have used that code and it still deletes the first record no matter which 'remove' button is clicked (when it is inside the subform on any subsequent added sections that are added by clicking on an add record button within each subform).
Sorry if this doesn't make sense.
Views
Replies
Total Likes
Hi,
Can you share your script? Also include the names of the subforms. I'll get to it when I can.
Niall
Views
Replies
Total Likes
I have this on the 'click' event to add an instance of the subform.
_ontreatment.addInstance(true);
xfa.form.recalculate(true);
and I have this on the 'click' event wanting to remove that particular subform instance.
_ontreatment.removeInstance(this.parent.index);
xfa.form.recalculate(true);
the subform is called 'ontreatment'
and I have this on the 'click' event wanting to remove that particular subform instance.
Both buttons sit inside the subform. I need the user to be able to add a record and be able to delete that record by choosing the remove button.
Thanks for your help.
Views
Replies
Total Likes
Okay,
In the hierarchy check the relative path from the remove button to the ontreatment subform. If, for example, the remove button is in another subform, you would need to take this into account when determining the index of the repeatable ontreatment subform:
_ontreatment.removeInstance(this.parent.parent.index);
Each "parent" refers to the container or subform.
Hope that helps,
Niall
Views
Replies
Total Likes
Thanks for that Niall - works perfectly.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies