These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Keeping Data binding index in synch with addInstance/removeInstance?

CESolomon
Registered: Jul 16 2010
Posts: 1

I am facing a curious problem which has me scratching my head (why else would I post here eh? haha).

This relates to repeatable rows (subform) of a table. EACH cell in a table row is data bound to a different backend field however they match in index across rows. So you can think of each column as an indexed array but looking across, all items in the arrays of the same index represent a row. This definition can not be changed (ie. the data layout/XLM is what it is).

To simplify this, let's consider on column of data or a row of only one cell.

So, I have data driven and defined from a backend framework. There, I have defined a field...let's say...AMOUNT_DATA and made it an array of 5 values (0-4 indexes).

Now, on my form, I have a table defined with a row (repeatable subform). I use all the good ol' "Add Row" (addInstance) and "Delete Row" (removeInsance) functions. Standing alone....this works great! The rows add or remove perfectly and the indexes on rows reset. For example, if I have rows:

0
1
2
3
and I select to remove row 2, it properly removes row 2 and re-indexes to
0
1
2

If I add a row, it simply picks up the next available index, so using the example above....

0
1
2

becomes

0
1
2
3

That's great!

Now the catch....If I have my table "cell" bound to data such as defined in the default binding as

$record.AMOUNT_DATA.DATA[*].FIELD

Consider the notation as "row index-bound data index".....so 0-0 would be row 0 - data 0.

here is what is happening....if I start with say 3 items defined from the backend(framework) and then on the form I first display my table with the rows/cell. It will match as....

0-0
1-1
2-2

Now, let's say I remove row index 1 with removeInstance so I have now...

0-0
1-2

If I then ADD a new row, it becomes
0-0
1-2
2-3

As you can see the indexes are completely out of synch. Furthermore since on the backend, I have only space for 3 items (index 0-2) when the values get passed back, the data with index 3 from the last row we added is DROPPED and the item with index 1 is blank (since we removed that row).

What I would LIKE to do is to "resynch" the indexes between the form field and the data fields when a row is removed. Back to the example above.....if we started with:

0-0
1-1
2-2

and we remove the row index 1. I would like for the data indexed at 1 to CLEAR it's value, and then the next data index at 2 to be written to it and then index 2 cleared. In effect....shift the data indexes up to synch with the form field indexes.

Make sense? I just am not finding any way to do this via script. At the moment, I can only allow "Add Row" or "Clear All" since both keep the integrity of the matching indexes.

Help? Thoughts? Ideas?

Thanks in advance!

sconforms
Expert
Registered: Jul 10 2007
Posts: 92
@CESolomon,

Is your data coming from a database or an XML data file?

Also, it sounds like you have enough data for, say 10 rows, but you're choosing to only display 3 of the 10 at once or initially. Is that correct?

One way to control this would be to not use bindings within your table (since with bindings, you're subject to merging algorithm rules which come into play when you add more rows which are bound to data -- a subform will not bind to the same data node more than once, which is likely why new rows you add bind to data nodes beyond those to which the removed rows were bound) and programmatically add/remove rows, manually feeding the right data into them based on the form's Data DOM.

Stefan
Adobe Systems

Stefan Cameron obtained his bachelor's degree with Honors in Computer Science at the University of Ottawa and is a Computer Scientist working on Adobe's LiveCycle server products, in particular on LiveCycle Designer ES for the past 5 years.