Expand my Community achievements bar.

Help with accessing radio buttons inside an instanced subform.

Avatar

Level 4

Attached is a file illustrating the issue.

I have added 3 "check all" buttons at the top of 3 columns. there is also a subform at the bottom containing a textbox for "other" information, as well as 3 identical radio buttons to those above it.

As it is now, if any of the check all buttons are pushed, all works well. Clicking on any other buttons within the array will cause the aforementioned check all button to become unchecked.

How do I make it so the check all button works on any newly created instances?

Thanks!

Graham

6 Replies

Avatar

Level 10

Hi Graham,

You need to loop through the number of occurrences of the repeating subform and change the rawValue of each one in turn.

     var oRows = xfa.resolveNodes("CHILD01.#subform.Other[*].R54");

     var oNodes = oRows.length;
    
     for (var i = 0; i < oNodes; i++)
     {
          xfa.resolveNode("#subform.Other[" + i + "]").RadioButtonList.plaintiff.rawValue = "1";
     }

Here is the form with the first rule amended.

Good luck,

Niall

ps. just a small point from the performance point of view, you could use the caption on each of the radiobuttons instead of the static text. You can have the caption on different sides of the circle (set via the Layout tab). Also I would be inclided to name subforms and objects as you go, to avoid duplicates and having to resolveNodes. If you have to resolve a node a lot of times in a script you can set up a variable at the start of the script and then everytime afterwards refer to the variable, something like this:

var oRef = xfa.resolveNode("form1.page1.subform1.anotherSubform");


...

oRef.textField1 = "Hello";

oRef.textField2 = "world!";

...

This might help speed things up.

Avatar

Level 4

Niall,

I'm looking through what you sent me... so much to learn.

Quick question, in your JS, you wrote:


    var OtherRows = xfa.resolveNodes("CHILD01.OTHER_PARENT.other_child[*].R54");
    var oNodes = OtherRows.length;
    
    for (var i = 0; i < oNodes; i++)
    {
        xfa.resolveNode("OTHER_PARENT.other_child[" + i + "]").RadioButtonList.plaintiff.rawValue = "1";
    }
}

What is the purpose of that line in red?

Graham

Avatar

Level 10

Hi Graham,

The first variable counts the number of nodes (e.g. the number of "Other" fields). The second variable (in red) converts this into a number. This is what is needed when looping through the radiobuttons.

When dealing with repeating rows in a table you can use .index to get the number of rows. I have had difficulty with this with repeating subforms, so counting the times a subform is repeated seems to work.

One small point, when you are resolving a single node the script is    xfa.resolveNode("...

But when resolvign multiple nodes you need    xfa.resolveNodes("...

If you want to see this in action,put the following line after the line in red:

console.println("oNodes: " + oNodes);

Then when previewign the form in Acrobat press Control+J to open the javascript console. Each time you add a row the console with output the current number.

Good luck,

Niall

Avatar

Level 4

Thanks again, Niall.

Another quick question: In writing your variables

var OtherRows = xfa.resolveNodes("CHILD01.OTHER_PARENT.other_child[*].R54");

You specifiaclly reference R54. Why is that? Even though there are other objects in the subform, you don't mention them, nor does R54 hold any particular prominence; it's just another object in the subform.

I have attached the form. Look in "form1.page1.CUSCHILD.childList2nd.#subform[0].CHILD01.RadioButtonList[0].plaintiff::change" for quick reference.

Thanks!

Graham

Avatar

Level 10

Hi Graham.

I just picked an object in the repeating subform. It could have been any object, it doesn't matter. I have just checked and it still works even if you only count the repeating subform itself.

var OtherRows = xfa.resolveNodes("CHILD01.OTHER_PARENT.other_child[*]");

Some else might have more advice on scripting best practice for this task.

The script in the form is working OK. I know I suggested putting in the console.println line, but that is really for development / debugging. You can comment it out by placing // in front of the line.

Hope that helps,

N.

Avatar

Level 4

Thanks Niall. Your reply was very helpful.

I consider this question answered.

Graham