Expand my Community achievements bar.

How to find index of row in dynamic table?

Avatar

Level 1

Our form has a table to which the user can add rows.  We want to be able to edit the custom help text of each field in the row to add the row number for accessibility.  But need the index number of the row to reference the row of the fields. And we can't figure out how to get it.

We have tried both the field initialize and field layout events, but our property for index is not being recognized. For the initialize event of one of the fields in the row, we wrote this code:

xfa.host.messageBox("We are in the initialize event for this field.");

var thisRow = this.parent.index;

xfa.host.messageBox(thisRow);

We have the table set up with 8 intial rows. The first message pops up 8 times, but the second doesn't appear at all.  How can we get the number of the row we are addressing?

Thanks.

1 Reply

Avatar

Level 10

Not sure what's going on there but messageBox() is throwing an error for some reason (use CTRL-J in Acrobat to open the Console):

GeneralError: Operation failed.

XFAObject.messageBox:3:XFA:form1[0]:subMain[0]:Table1[0]:Row1[1]:TextField1[0]:ready

Argument mismatch in property or function argument

It works if you add some text:

xfa.host.messageBox("Row Number: " + thisRow);

app.alert() works: app.alert(thisRow);

And console.println() works (less annoying for testing than popups - open the Console window to see the results):

console.println(thisRow);

Ah, just figured it out - messageBox() doesn't seem to like a number first, it's expecting a string. The following works with your original script:

var thisRow = this.parent.index.toString();