Expand my Community achievements bar.

Renumbering Boxes (should be simple, right?)

Avatar

Former Community Member

This problem should be simple, but so far it's been harder than it looks.

I have a repeating subform which has a read-only Text Field which is used to number the subform.  Instance one of the subform causes the Text field to have a 1, instance 2 a 2, etc.  for each instance as the user adds instances.  If the user added instances so that there are ten of them, the Text fields would be numbered 1 to 10.  This works just fine. 

The problem occurs when the user removes a subform.  Let's say the user has added subforms so that there are ten of them and then deletes the first subform.  I want the Text fields to be renumbered 1 to 9, but they redisplay  with numbers 2 - 10. 

Here's the code for the click event on the remove button:

//  first, remove the selected instance of the subform

if (this.parent.instanceManager.count > 1) {

     parent.removeInstance(this.parent.index);

}

// remumber the number blocks

for (i = 1; i < parent.instanceManager.count + 1; i++) {

    parent[i].ItemNo.rawValue = i;

}

I thought the code would simply go through each rawValue of the field I am trying to reset after the instance was removed, but it doesn't work.

The count is correct after I execute the removeInstance method.  I used app.alerts to verify that.  It's the rawValues that don't seem to change.

Am I doing this in the wrong event?  Am I changing the wrong property?  Is there another property I need to change temporarily to reset the rawValue here?

3 Replies

Avatar

Level 6

this is very simple to fix....in this scenario I would use following code in ReadOnly textField under "layoutReady" event to always adjust the sequence number them self rather than you assign the numbers with your code.....

//TextField:layoutReady event

this.rawValue = this.parent.index + 1 // you would have SOMexpression reading the index of the repeating element you may have to adjust the code like this.parent.parent.parent.index depending on your situation....

and then clean the following code from your instanceManager...

// renumber the number blocks

for (i = 1; i < parent.instanceManager.count + 1; i++) {

    parent[i].ItemNo.rawValue = i;

}

Good Luck,

Avatar

Former Community Member

Thanks. It worked. I had that code in the initialize event for my Text field. It's still there. I figured that I had code to reset the field value in the wrong event, but I didn't know what the correct event was.

Avatar

Former Community Member

Thanks. It worked.  I had that code in the initialize event for my Text field. It's still there.  I figured that I had code to reset the field value in the wrong event, but I didn't know what the correct event was.