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

How to address a specific field in a table

Lea1337
Registered: Jul 14 2009
Posts: 64
Answered

I have created a table, and am not really that experienced with tables, so I just need a little help with the syntax.

The table is dynamic - the user can add and remove rows, and this works just fine. My problems is this: the first row is filled with default values in all fields. When the user adds a row, the new row conatins the same default values (of course), but I don't want that, I want blank fields. So I need a way to reference the different fields in the last added row, so I can set their values to a blank state.

My table is built up something like this:

Trainingtable
- Row0 (which I use as header row)
- Row1 (which is the row that gets repeated)
- Date (textfield)
- Duration (textfield)
- Tasks (textfield)
- Responsible (textfield)

So it's the textfields I want to reach, how can I do that? I have managed to find the "length" of the current table:

var rowindex = Trainingtable.Row1.instanceManager.count;

but after that I'm kind of lost :-p

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If all rows except the first one are to be blank, then why do they have default values? If Row and Row1 have different behaviors then they should be different subforms, not repeats of the same field. If you are using Row0 as a header then I would image that it's meant to be static, i.e., not edited by the user?

So I have two suggestions:
1. Make Row0 a different animal, static text or at least a different subform.
2. If there is some compeling reason that Row0 needs to be the same subform as the other rows then set the default values to blank. Then use the forms initialize event to ensure that Row0 has the values in it that you want.

To get to a specific instance of a subform you need to use the resolveNode() fucntion.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Lea1337
Registered: Jul 14 2009
Posts: 64
Maybe I was a bit unclear when I described my problem, but I see that (as most often is the case), it can be solved in a much easier way that I didn't think of (or sometimes know of). I'm still kind of a newbie on a lot in LiveCycle/Javascript, so I'm probably asking a lot of stupid questions :-)

Well, anyway, as you said I could easily use the 'initialize' event to fill Row1 with data (this
row is supposed to work as an example for the user, so that he/she can see how the table is meant to be filled). I hadn't really thougth of using the 'initialize' event, but it is of course the best solution and now I don't have to worry about having to remove default values when rows are being added.

But I'm not quite sure if I followed the rest of your suggestions. In this case I am not using subforms to organize and add rows, I'm just using the table:

...Main_subform.Training_subform.Trainingtable._Row1.addInstance(1);

Row1 also contains a delete-button, so removing rows is also easy to do:

..Main_subform.Training_subform.Trainingtable._Row1.removeInstance(this.parent.index);

Row0 is the header row (defined in 'Type' in the Object palette), and the user cannot edit this row. Maybe I am doing this the wrong or mucky way, but it's working quite nicely now :-)

Thanks for the help!
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Thanks for explaining this better. I didn't realize the first row was being used as an example. That makes much more sense.

My second idea was that if your example line is meant to be static and uneditable, then it should not be part of the dynamic editible structure. The rows in a table are really a specialized type of subform. So rather than using the table row, place the example row in a subform immediately above the table. To the user it would look exactly like a row in the table.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script