Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Loop through a table

Avatar

Level 2

Is it feasible to write code that loops through a table in a form? I'm currently writing separate sections of code for each row of a five-row table to validate data entries.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

It would be easier if your table contained one row that repeated with an initial count of five (this is set in the binding tab of the Object palette).  This will change the XML generated but assuming that is not a problem your could loop though your table with the code;

    var rows = this.resolveNodes("Table1.Row1[*]");

    for (var i=0; i<rows.length; i++)

  {

        var currentRow = rows.item(i);

        .

        .

        .

  }

If you do need the rows uniquely named then you could pass i and the result of "this.resolveNodes("Table1.Row"+i)" into a function.

This is you form back ... with only the first validation converted to the new approach.

https://acrobat.com/#d=akb0*Ptvdr3KSYN0VP*7zA

Hope this gets you started.

Regards

Bruce

View solution in original post

4 Replies

Avatar

Level 6

It actually depends on scenario....you need to post more details about your request and if possible share the form.....most codes segments are base on hierarchy and actions you would like to perform.

Avatar

Level 2

Here's the form.

https://acrobat.com/#d=tc-tH46jIH8xx7i6pT60Rw

I was having issues with links earlier.

The validation occurs in the click event of btnSubmit.

Avatar

Correct answer by
Level 10

Hi,

It would be easier if your table contained one row that repeated with an initial count of five (this is set in the binding tab of the Object palette).  This will change the XML generated but assuming that is not a problem your could loop though your table with the code;

    var rows = this.resolveNodes("Table1.Row1[*]");

    for (var i=0; i<rows.length; i++)

  {

        var currentRow = rows.item(i);

        .

        .

        .

  }

If you do need the rows uniquely named then you could pass i and the result of "this.resolveNodes("Table1.Row"+i)" into a function.

This is you form back ... with only the first validation converted to the new approach.

https://acrobat.com/#d=akb0*Ptvdr3KSYN0VP*7zA

Hope this gets you started.

Regards

Bruce