Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Button that hides all empty fields

johnnyp32387969
Level 2
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
radzmar
Correct answer by
Level 10
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
radzmar
Correct answer by
Level 10
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

johnnyp32387969
Level 2
Level 2

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

johnnyp32387969
Level 2
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.

radzmar
Level 10
Level 10

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

MinusZero
Level 7
Level 7

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