Expand my Community achievements bar.

SOLVED

Button that hides all empty fields

Avatar

Level 2

I have a form with multiple pages and subforms.  I would like a button that would search the form for all empty fields, and then hide them.  Is there a simple way of achieving this?

1 Accepted Solution

Avatar

Correct answer by
Level 10

You can do so with a recursive function.

function changeFields (oNode) {

    if (oNode.className === "field") {

        if (oNode.isNull) {

            oNode.presence = "invisible";

        }

    }

    for (var i = 0; i < oNode.nodes.length; i += 1) {

        changeFields(oNode.nodes.item(i));

    }

}

changeFields(xfa.form); // call the function

View solution in original post

6 Replies

Avatar

Correct answer by
Level 10

You can do so with a recursive function.

function changeFields (oNode) {

    if (oNode.className === "field") {

        if (oNode.isNull) {

            oNode.presence = "invisible";

        }

    }

    for (var i = 0; i < oNode.nodes.length; i += 1) {

        changeFields(oNode.nodes.item(i));

    }

}

changeFields(xfa.form); // call the function

Avatar

Level 2

Is this as simple as creating a button and applying the code in the "click" script? 

Avatar

Level 2

It doesn't seem to be doing what I hoped.  The button just thinks for a second and then nothing.  Do you know what I might be doing wrong?  Thanks for the quick reply's, much appreciated.

Avatar

Level 10

There was a closing bracket missing in the script above. I corrected it, so try it again.

Avatar

Level 7

Awesome code. I will add that to my database of code tutorials.