Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Table rows functionality with passing data and instances

Avatar

Level 3

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?

Img1.PNGImg2.PNGImg3.PNG

Img4.PNGimg5.PNGImg6.PNGImg7.PNGImg8.PNG

Thanks for all the help and suggestions in advance

Shai

1 Accepted Solution

Avatar

Correct answer by
Level 10

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.

Capture.PNG

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

View solution in original post

13 Replies

Avatar

Level 10

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

Avatar

Level 3

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

Avatar

Level 10

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

Avatar

Level 3

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

Avatar

Level 10

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

Avatar

Level 3

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

Avatar

Level 10

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

Avatar

Level 3

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

Avatar

Correct answer by
Level 10

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.

Capture.PNG

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

Avatar

Level 3

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

Image2.PNG

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).

Image1.PNG

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

Avatar

Level 10

Hi Shai,

That is a strange warning message to get in Acrobat, that is the sort of message I would expect with Reader if the form has not been extended.

Not sure about your SUM expression, that seems to be a new part to your form, maybe you will have to share the for again.

Bruce

Avatar

Level 3

So here is the new and improved form. I implemented the new changes to

the Table1, where every check box does now behave as predicted with new

instances and fields are filled appropriately.

So new issue is how to script a JavaScript (as oposed to FormCalc) in

calculating all the amount fields in the table. I have it working using

formcalc eventhough it throws an error.

Other issue(s):

Form does not allow printing or saving - very odd indeed.

And how can I calculate a follow-up date via JavaScript, taking into

account the Date of Service date (DOS) field.

Here again is the link to the latest form:

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

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

<cid:part1.02080408.00040707@yahoo.com>

Thanks in advance

Shai

Avatar

Level 10

Hi,

The SUM expression is failing because those fields have not yet been added to the form, so if you check for their existance first you should be ok.

if (Exists(Patient_info.Table1.Data[0].amt[0])) then

    $ = Sum(Patient_info.Table1.Data[*].amt[*].rawValue)

endif

So you can still stick with FormCalc.

You can calculate a day in the future based on the Date Of Service, using (for example using 14 days);

Num2Date(Date2Num(Invoice_info.DOS, "YYYY-MM-DD") + 14)

I've updated the form with these two changes, https://workspaces.acrobat.com/?d=7j8MuoO37xAttiE8Q0N69Q

Not sure about why the form can not be printed or saved.  Can you save/print other forms, or even other PDF's.  I have Acrobat XI (11.0.5) and Reader X (10.1.8)

Bruce