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

Accessing Widgets from within an "Array" or "Table"

Scooter1979
Registered: Oct 23 2010
Posts: 2

I hope I am putting this in the right Forum Topic... Anyway, I am needing to create a large array of information... 5 columns wide, by 40 rows... Creating them is not the issue, I need to access the information in multiple fields on every row, so I would like to write the javascript just once and let it copy with the original elements... Here's the layout...
 
ChkBox Total Value_A Value_B Value_C
 
It should be noted that the Check Box is returning a numeric value, Value_A is a calculated value from outside the array (but will differ with each row), Values B and C are user input... It is with the Total that I am having the problem... I need it to Take the value returned from ChkBox, process it a little, add it to all of the Value_X entries to come up with a total.
 
Is there anyway to tell Total to access the values.0 or .1 or whatever respectively using just the field names and let it copy as Acrobat makes the table?
 
Thank you for any input!
 
Scooter

Scooter

~Not all who wander are Lost~ J.R.R. Tolkein

My Product Information:
Acrobat, Windows
George_Johnson
Online
Expert
Registered: Jul 6 2008
Posts: 1876
You may need to provide more information about how you have things set up. What do you mean by "...as Acrobat makes the table."? Are you using the "Place Multiple Fields" feature, so that you end up with field names like, "values.0.0, values.0.1, values.1.0, values.1.1", etc? If so, in the Calculate field event you can get the field name and parse out the row and column numbers and use them in the script to get the correct input values. For example:

// field name is "values.2.1"
var field_name_parts = event.target.name.split(".");

The value of the variable field_name_parts will be an array. The first element (field_name_parts[0]) will be the string "values", the second element (field_name_parts[1]) will be the string "2" (row identifier), and the last element (field_name_parts[2]) will be the string "1" (column identifier).

So you can now do:

// Get the value of "Value_A" field for this row
var v1 = getField("values." + field_name_parts[1] + ".2").value;

// Do the same for the other input fields




try67
Expert
Registered: Oct 30 2008
Posts: 2398
Why do you need to access a widget in order to calculate a total? A widget doesn't have a value. The "parent" field is the one that holds the value. A widget is just used for the visual representation.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Scooter1979
Registered: Oct 23 2010
Posts: 2
George_Johnson wrote:
You may need to provide more information about how you have things set up. What do you mean by "...as Acrobat makes the table."? Are you using the "Place Multiple Fields" feature...
Yes this is exactly what I am doing... Unless there is a better way...

George_Johnson wrote:
// field name is "values.2.1"
var field_name_parts = event.target.name.split(".");
Not sure if it is important or not, but the original field names have no .0 or .1 or anything... The output fields have those... and each of the five columns are pre-defined before making the table.

George_Johnson wrote:
The value of the variable field_name_parts will be an array. The first element (field_name_parts[0]) will be the string "values", the second element (field_name_parts[1]) will be the string "2" (row identifier), and the last element (field_name_parts[2]) will be the string "1" (column identifier).
All I really need it to do is identify the rows, as the calculations only occur across them, and as I said above, the columns have unique names already.

George_Johnson wrote:
So you can now do:// Get the value of "Value_A" field for this row
var v1 = getField("values." + field_name_parts[1] + ".2").value;

// Do the same for the other input fields
I will admit, I am no javascript guru, but this looks like I am still going to have to edit every field in order to put in the row identifier... That is what I am hoping to avoid... Am I mistaken? Since my field names are more like ChkBox.0 will the following work?

var v1 = getField("values." + field_name_parts[1]).value;

AND will it function properly as the fields are created by Adobe? Thanks for the help!

Scooter

~Not all who wander are Lost~ J.R.R. Tolkein

George_Johnson
Online
Expert
Registered: Jul 6 2008
Posts: 1876
The row identifier is extracted by the code from the name of the field that is calling the calculation script. So no, you do not specify any row identifiers. I was going off assumptions I made regarding the field naming, since you didn't include all of that info. You can choose a field naming convention for your grid of fields that will make the scripting simpler. Otherwise, it will be more complex. That's up to you. If you provide the actual field names for a row of fields, that would help.

I'm not sure what your last question means exactly, but my suggestions we intended for fields created in Acrobat, not LiveCycle Designer.