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

ArrueiraVermelh

07-08-2015

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!

Accepted Solutions (1)

Accepted Solutions (1)

_Bruce_Robertson

MVP

08-08-2015

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

Answers (1)

Answers (1)