Expand my Community achievements bar.

Subform problem

Avatar

Level 4

Hi All

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? 

8 Replies

Avatar

Former Community Member

So if I have subforms 1 2 3 and 4. And I remove subform 2 do you want then to renumber to 1 2 3 or 1 2 4?

Paul

Avatar

Level 4

Hi Paul

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.

Thanks

Darren

Avatar

Former Community Member

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:

subformName.instanceManager.removeInstance(this.parent.index)

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

Avatar

Level 10

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.

Avatar

Level 4

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.

Darren

Avatar

Level 4

Hi Paul

What does the instanceIndex do exactly?  As I was also trying to get it to work using this as well.

Thanks

Darren

Avatar

Former Community Member

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.

Paul

Avatar

Level 4

Many thanks for clearing this up for me Paul. That has made things clearer.

Best wishes

Darren