Table rows functionality with passing data and instances | Community
Skip to main content
Level 3
November 10, 2013
Solved

Table rows functionality with passing data and instances

  • November 10, 2013
  • 13 replies
  • 9731 views

My form setup is as follows:

I have several check boxes overlaid on an image. Each box will have several actions associated to it (more on this in a minute).

I have a Table that will take in some data, depending on what check boxes are checked and unchecked.

Several things are happening as follows:

A table is setup with the following headers and respective rows - vial#(txt), location(txt), area(txt), amount(dropdown), price(dropdown), cost(calculated - eval(amount * price)).

When a check box is selected the following actions ensue:

location and area are filled with text values [ Condition: when box FR0 is checked;  Result: set value of location to be some text, value of amount to be some text, set vocus on amount ]

When a check box is unselected the following actions ensue:

all fields are set to null.

NOTE: this actions work great with the first checkbox.

Now the issue at hand:

When the next checkbox is selected, what should happen is this: a new instance of the rows should appear, location and area should be automatically filled out in same manner as above and focus should be set on amount.

What happens is this: a new instance is created, focus is set on amount, but the 2 fields are not populated as in above example.

Next: When the other checkbox is unselected, the following should happen: the latest instance should dissapear and all cell values of last instance should be null.

What happens is this: the last instance goes aways but all the vlaues on original row (text only) also are set to null.

Now I know this setup is a mere issue with how I have my Table and subforms setup. So here is the setup of the form (also note images):

Row1 is under a Subform Values_subsection. Type: use all subforms in order / Binding: repeat section for each data item

Row1 has: Allow page breaks with content / Binding: repeat row for each data item

So where am I going wrong?

Thanks for all the help and suggestions in advance

Shai

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by _Bruce_Robertson

Hi Shai,

I think what you are trying to do is not supported by the action builder.  But can be done with your own scripting, I have added a script object which contains a custom script that will do what you want, I called it "Script" (see image below).  Select this object and then "All Events" under show in the script editor (ctrl-shift-f5) to see what I have done.

This now means that each checkbox change event needs the following JavaScript code;

Script.Change(this.rawValue, "FR 1", 100);

The first parameter is the value of the check box (1 for selected, 2 for unselected), the second the location, and the third the amount).

The Change funtion in the Script object looks like

function Change(newValue, location, amount)

{

    if (newValue == "1")

    {

      var newRow = Patient_info.Table1._Data.addInstance(1);

      if (xfa.host.version < 8) {

        xfa.form.recalculate(1);

      }

      newRow.loc.rawValue = location;

      newRow.amt.rawValue = amount;

      xfa.host.setFocus(newRow.amt);

    }

    else

    {

        var rows = Patient_info.Table1.resolveNodes("Data[*]");

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

        {

            var row = rows.item(i);

            if (row.loc.rawValue == location)

            {

                Patient_info.Table1._Data.removeInstance(row.index);

                break;

            }

        }

    }

}

You should see some similarity with what action builder produced.

I have only done the first row of checkboxes (the first four), but here is my version of your form I modified to check the above code worked.

https://workspaces.acrobat.com/?d=7j8MuoO37xAttiE8Q0N69Q

You may have to reselect the image of the face again as this was not included in the form you uploaded.

Hope this helps

Bruce

13 replies

_Bruce_Robertson
Level 10
November 11, 2013

Hi Shai,

You may have to share your form for me to understand what you are trying to do.  I don't understand how each checkbox is going to know which row of the table it has become associated with.

Regards

Bruce

ShailevitAuthor
Level 3
November 11, 2013

Hi Bruce,

Sure please find the entire form attached. I looked at a few examples

and even added more table-type sub-forms, but it is still not behaving

as I would like.

Similarly, is there a way to transpose one field value from a text to

another on another page?

Thanks in advance

Shai

_Bruce_Robertson
Level 10
November 12, 2013

Hi Shai,

There isn't a link to your form in your last post.

There are several ways to link the values of multiple fields.  You can bind them to the same value or maybe use a calculation script.

Bruce

ShailevitAuthor
Level 3
November 12, 2013

Hi Bruce,

I have attached my latest version of the document. So I do have a link

from the check box. It's an action script that says: if I check the box,

two fields in the table are populated with text and then there is a

focus on the third field. That part works fine. I can even control the

uncheck box action script that put all values to null.

My issue lies in the fact that when I check the next box, I need another

instance of the Table (one row) to populate.

So what happens is the new instance of the row is created, but the

original fields are now over-written with the text being passed to the

new text field.

i.e.: the next check box need to populate the two text field with new

data via the action script and put focus on the amount field. What

happens is that a new row instance is created, but nothing is filled out

and the instance above is overwritten with the new data fields. Removing

the instance is no problem again.

Hope this explains it. So my thoughts are there is a way to control via

some-sort of subform type instance the creation of a new row that does

not overwrite the previous fields. Some type of wrap I am missing. I

tried several ways, but still dumbfounded at way they do not work.

Thanks

Shai

PS: I am using LC ES4

_Bruce_Robertson
Level 10
November 12, 2013

Hi Shai,

I still see can't your form, you will need to upload it to Acrobat.com, Google Docs, DropBox or the like, share the form and post a link to it in this thread.

Regards

Bruce

ShailevitAuthor
Level 3
November 13, 2013

Hi Bruce,

My apologies (newbies, I tell you). So here is the link to the document>

https://workspaces.acrobat.com/?d=gXLN793XZjRXpTkNJS6Q

Note: Issue is with text being overwritten and new instance of table row

not passing on new action.

Thanks

Shai

_Bruce_Robertson
Level 10
November 14, 2013

Hi Shai,

There seems to be a couple of characters missing from the URL you have posted, at least I am not able to access your form.

Can you make sure the form is shared and try pasting the URL again.

Thanks

Bruce

ShailevitAuthor
Level 3
November 14, 2013

I have made a few changes to the form, but the same problem still

persists. Please find the link for the form. Again it is an issue with

cells being overwritten during an action script when a new instance of

table rows is created. I think looking at the script I see the issue,

but am perplexed at how to correct it. I also included the action script.

Action script for check box one:

Type: Action

//+ Result3: SetFocus("$Node4")

//+ Result2: SetFieldValue("$Node3","tovalue","FR 1")

//+ Result1: AddInstance("$Node2")

//+ Node4:

form1[0].Patient_info[0].Table1[0].Log_subsections[0].Row1[0].amt[0]

//+ Node3:

form1[0].Patient_info[0].Table1[0].Log_subsections[0].Row1[0].loc[0]

//+ Node2: form1[0].Patient_info[0].Table1[0].Log_subsections[0].Row1[0]

//+ Node1: form1[0].Patient_info[0].Image_Botox[0].FR1[0]

//+ Condition1: CheckBox("$Node1","checked")

//+ ActionName: FR1.change

if (this.rawValue == "1") {

this.resolveNode('').addInstance(1);

if (xfa.host.version < 8) {

xfa.form.recalculate(1);

}

this.resolveNode("").rawValue = "FR 1";

xfa.host.setFocus("");

}

//-

Action script for check box two:

Type: Action

//+ Result3: SetFocus("$Node4")

//+ Result2: SetFieldValue("$Node3","tovalue","FR 2")

//+ Result1: AddInstance("$Node2")

//+ Node4:

form1[0].Patient_info[0].Table1[0].Log_subsections[0].Row1[0].amt[0]

//+ Node3:

form1[0].Patient_info[0].Table1[0].Log_subsections[0].Row1[0].loc[0]

//+ Node2: form1[0].Patient_info[0].Table1[0].Log_subsections[0].Row1[0]

//+ Node1: form1[0].Patient_info[0].Image_Botox[0].FR2[0]

//+ Condition1: CheckBox("$Node1","checked")

//+ ActionName: FR2.change

if (this.rawValue == "1") {

this.resolveNode('').addInstance(1);

if (xfa.host.version < 8) {

xfa.form.recalculate(1);

}

this.resolveNode("").rawValue = "FR 2";

xfa.host.setFocus("");

}

//-

Link to document on Adobe Acrobat.com workspaces:

https://workspaces.acrobat.com/?d=0JMtP6BxZwILKdnkO-yUfA

https://workspaces.acrobat.com/?d=0JMtP6BxZwILKdnkO-yUfA

<cid:part1.06090405.06060300@yahoo.com>

Again my apologies for a non-working link previous. And thanks in

advance for all the help and assistance.

Shai

_Bruce_Robertson
_Bruce_RobertsonAccepted solution
Level 10
November 15, 2013

Hi Shai,

I think what you are trying to do is not supported by the action builder.  But can be done with your own scripting, I have added a script object which contains a custom script that will do what you want, I called it "Script" (see image below).  Select this object and then "All Events" under show in the script editor (ctrl-shift-f5) to see what I have done.

This now means that each checkbox change event needs the following JavaScript code;

Script.Change(this.rawValue, "FR 1", 100);

The first parameter is the value of the check box (1 for selected, 2 for unselected), the second the location, and the third the amount).

The Change funtion in the Script object looks like

function Change(newValue, location, amount)

{

    if (newValue == "1")

    {

      var newRow = Patient_info.Table1._Data.addInstance(1);

      if (xfa.host.version < 8) {

        xfa.form.recalculate(1);

      }

      newRow.loc.rawValue = location;

      newRow.amt.rawValue = amount;

      xfa.host.setFocus(newRow.amt);

    }

    else

    {

        var rows = Patient_info.Table1.resolveNodes("Data[*]");

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

        {

            var row = rows.item(i);

            if (row.loc.rawValue == location)

            {

                Patient_info.Table1._Data.removeInstance(row.index);

                break;

            }

        }

    }

}

You should see some similarity with what action builder produced.

I have only done the first row of checkboxes (the first four), but here is my version of your form I modified to check the above code worked.

https://workspaces.acrobat.com/?d=7j8MuoO37xAttiE8Q0N69Q

You may have to reselect the image of the face again as this was not included in the form you uploaded.

Hope this helps

Bruce

ShailevitAuthor
Level 3
November 15, 2013

Thanks Bruce,

That JavaScript worked great and performed as I expected. My only other small trivial issues are these:

  • When I open the Form in Adobe Acrobat XI, I get a warning message:

          Cannot save form information

eventhtough I made sure that the security of the form (in LC ES4: File -> FormProperties) is disabled to allow form saving.

  • Also I added a script using Action Script, which basically adds all the amount values in the amount of the Table1 and Sums them. The function works fine, except I still get an error message (image below).

I am guessing I will have to convert this to match the JavaScript... xfa format to make the calculations.

Again thanks for all the help and solving the issue at hand. Much appreciated.

Shai