Expand my Community achievements bar.

SOLVED

Drop down box and Dynamic presence

Avatar

Level 3

I hope this makes sense.

I have a drop down box with several values in it. Based on the user's selection, different fields and subforms will either be visible or hidden. To do this, I built a switch statement on the exit event of the drop down box. The statement works great until I start introducing dynamic properties to one of the subforms.

Two of the fields in one repeating subform need to be hidden or set back to visible depending on the choice in the drop down box. However, once you have added multiple instances of the subform, it only hides/displays the FIRST field in the subform. I need it to hide/display ALL of those fields when the subform is repeated.

To do this, on the first selection, I created a for statement to go through all of the instances and set all of those fields to hidden or visible as needed. However, it's not working. At all. Even on the first instance like it used to.

I hope I'm making sense. Here is the code I am using for my for statement:

var indNum = xfa.resolveNodes("RequestDetails.RepeatingSection[*].serialNum");

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

    xfa.form.form1.Page1.RequestDetails.RepeatingSection(i).serialNum.presence = "visible";

    xfa.form.form1.Page1.RequestDetails.RepeatingSection(i).requestedNum.presence = "hidden";

}

1 Accepted Solution

Avatar

Correct answer by
Level 3

So, I figured out most of it myself. Even though EVERY bit of documentation I see says to reference the fields like this:

xfa.resolveNode("OuterSubform.InnerRepeatingSubform[i]");

I found that it doesn't know what to do with the brackets, so I have to:

.InnerRepeatingSubform["+i+"]");

So my final code ended up looking like this:

var indNum = xfa.form.form1.Page1.RequestDetails.RepeatingSection.instanceManager.count;

for (var i=0; i < indNum; i++) {

    xfa.resolveNode("RequestDetails.RepeatingSection["+i+"]").serialNum.presence = "hidden";

    xfa.resolveNode("RequestDetails.RepeatingSection["+i+"]").requestedNum.presence = "hidden";

}

I am still having one problem, though. If I have already added the subforms, and then select the drop down option, it works great! However, if I select a drop down item, THEN add rows, the added rows have visible fields that I would like to stay hidden. Is there a way I can call the case statement back when clicking a button? Or do I need to put in another switch or if statement on the buttons? I think it'd be easier if I could just call the swtich statement on the drop down list again. Unfortuantely, I don't know how to do that.

View solution in original post

6 Replies

Avatar

Correct answer by
Level 3

So, I figured out most of it myself. Even though EVERY bit of documentation I see says to reference the fields like this:

xfa.resolveNode("OuterSubform.InnerRepeatingSubform[i]");

I found that it doesn't know what to do with the brackets, so I have to:

.InnerRepeatingSubform["+i+"]");

So my final code ended up looking like this:

var indNum = xfa.form.form1.Page1.RequestDetails.RepeatingSection.instanceManager.count;

for (var i=0; i < indNum; i++) {

    xfa.resolveNode("RequestDetails.RepeatingSection["+i+"]").serialNum.presence = "hidden";

    xfa.resolveNode("RequestDetails.RepeatingSection["+i+"]").requestedNum.presence = "hidden";

}

I am still having one problem, though. If I have already added the subforms, and then select the drop down option, it works great! However, if I select a drop down item, THEN add rows, the added rows have visible fields that I would like to stay hidden. Is there a way I can call the case statement back when clicking a button? Or do I need to put in another switch or if statement on the buttons? I think it'd be easier if I could just call the swtich statement on the drop down list again. Unfortuantely, I don't know how to do that.

Avatar

Level 10

For the resolveNodes() syntax I think you want:

var sNum = xfa.resolveNodes("RequestDetails.RepeatingSection[*].serialNum");

var rNum = xfa.resolveNodes("RequestDetails.RepeatingSection[*].requestedNum");

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

    sNum.item(i).presence = "visible";

    rNum.item(i).presence = "hidden";

}

Avatar

Level 5

No joke GeneveX the documentation on this subject is very confusing because all the documentation I have read from Adobe and other online sources seem to be clear to access any instance of a repeating subform use brackets [ i ] with your loop variable. Where did [" + i +"]

come from?

Any ideas how to fix this form so I no longer get errors when I click the "Copy To BCC" button?

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

Avatar

Level 3

Here is what I have found, and I hope it is helpful. Where did ["+i+"] come from? It came from my brain, I guess. Trying to figure out some way of making it work, when all of the documentation's syntax seemed not to work. Even all of the books I have on Livecycle said that a simple [i] would work; but it doesn't within the resolveNode. I figured if it wasn't resolving the variable i, then maybe I needed to separate it out.

01371406, the only error I see with your form is a null error, which my form was doing do. I'm not entirely sure why it throws back null sometimes when it's done running through the loop; it should simply stop. Nonetheless, to fix it I simply integrated an if statement within my for loop to take care of it. An example of this from my code from earlier:

var indNum = xfa.form.form1.Page1.RequestDetails.RepeatingSection.instanceManager.count;
for (var i=0; i < indNum; i++) {

    if (xfa.resolveNode("RequestDetails.RepeatingSection["+i+"]") == null) {

          break;

    }

    xfa.resolveNode("RequestDetails.RepeatingSection["+i+"]").serialNum.presence = "hidden";
    xfa.resolveNode("RequestDetails.RepeatingSection["+i+"]").requestedNum.presence = "hidden";
}

Something else that I found while working on this same form, that might seem obvious to others but took me a while to figure out:

I have a switch statement with 7-8 case statements. Within each case statement, I have two for loops. The first loop I had made used the variable i and it worked fine. However, when I introduced the second for loop, also using the variable i, it freaked out and stopped working. So I switched to another variable. (In addition, the letters h, w, x, y are reserved letters; you can't use them) After switching the variable, it worked fine. So I copied the loop into the next case statement. The form broke again. Apparently I could use a for statement with the variable i in multiple cases, but not any other variable? I literally had to go through the alphabet with the second for loop in each case. What a pain. I still don't know why it was throwing a fit like that.

Avatar

Level 3

Also, I figured out my second problem as well--calling the switch statement again from another field.

On the add button click event to add another row, I put the following code:

// Call the exit event of the type of request drop down box, to change the visibility of the needed fields

xfa.resolveNode("Request.typeOfRequestDD").execEvent("exit");

That called the exit event of my drop down box again so that each time I add a row, it will run through the code and hide or display the fields I require.

Avatar

Level 10

Actually the documentation is pretty clear but there is a big difference between using resolveNode() and resolveNodes(). It can definitely get confusing because of the different methods that can be used.

Here's a good description:

http://blogs.adobe.com/formfeed/2011/06/resolvenode-vs-resolvenodes.html

Someone will probably have a better description than me but here's my take on it:

With resolveNode() you need to separate out the instance number because you are passing a string to the method. If you pass "Path.To.Repeating[i]" it's just a string. To get the instance variable from the loop in there you need to split the string and concatenate the variable into it: "Path.To.Repeating[" + i + "]".

With resolveNodes() you're not trying to pass a variable from a loop into the string, you are passing a list of objects with the wildcard [*]. You can then operate on that list of objects using object.item(i) - it's basically an array.