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



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 <; 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"





Accepted Solutions (1)

Accepted Solutions (1)





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?



Answers (1)

Answers (1)