I have a dynamic form that generates an additional subform on the click of a button. I want to put a textfield onto each subform that automatically assigns a number to that subform (i.e 1,2,3) so that the user knows which subform they are looking at (basically an identifier), as sometimes when the form expands it pushes back the previous subform and it can look like the data has been reset instead. I can get it to count the total number of subforms in the rawvalue of the textfield but not this. Can anyone help at all?
I have got it working so that you can only remove the previous subform added, therefore the numbers would always remain fixed on each subform. However I would also be interested in the answer if you removed a middle subform for it to then re number all subforms according to how many were left.
You can get the instance of the subform that you are on by using the parent.index property. Now that you have the instance you can use it in the removeInstance method of instanceManager. Assuming that you have a delete button on each subform the code would look something like this:
If you want to re-number the subforms then you coudl get a total count of subforms (subformName.instanceManager.count). Then create a for loop that will take each subform and update the number to the current count + 1 (subform instances are 0 based).
Paul, will this work the same as on table rows? I did a counter for table rows that is just this.rawValue=this.parent.index+1, if I add or delete a row in the table all the counters update - no looping required.
Hi Jono / Paul
I was struggling with getting this to work but I have tried Jono's example this morning and it is doing this correctly. Many thanks for both of your help on this.
I assume you mean parent.index? That will return to you the occurance number (index) of the parent container. So in your case where you have a delete button inside of each subform instance we can know which button inside of the particular subform instance was pressed.