Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

How do I hide fields based on their name (using a loop)?

Avatar

Level 3

I have a form that will require several fields to be hidden when the user first loads the form. I would like to automate that with a JavaScript loop where if the object name starts with "hid" set its presence to "hidden".

I found the script below in the LiveCycle ES4's documentation but it does nothing. No errors were reported in the JS console. Which event should the loop be added to? Of the parent form? Is the syntax correct for what I am trying to achieve?


for (var nPageCount = 0; nPageCount < xfa.host.numPages; nPageCount++) {



    var oFields = xfa.layout.pageContent(nPageCount, "field");


    var nNodesLength = oFields.length;



    for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) {


        if (oFields.item(nNodeCount).name.substring(0,3) == "hid") {


            oFields.item(nNodeCount).name.presence = "hidden"


        }


    }


}


Thanks!

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

On line 8 you need to remove the "name.", the presence is a property of the field, not the name. So;

oFields.item(nNodeCount).presence = "hidden"

You could put this code in the top subforms docReady event, or maybe it would be better in a macro, so that the fields are hidden at design time?

Regards

Bruce

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi,

On line 8 you need to remove the "name.", the presence is a property of the field, not the name. So;

oFields.item(nNodeCount).presence = "hidden"

You could put this code in the top subforms docReady event, or maybe it would be better in a macro, so that the fields are hidden at design time?

Regards

Bruce

Avatar

Level 3

Thank Bruce. It works great now!

I want to be able to see the fields in Design view so I am fine leaving the action at the docReady event.