Button that hides all empty fields

Avatar

Avatar

johnnyp32387969

Avatar

johnnyp32387969

johnnyp32387969

29-10-2018

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?

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

radzmar

MVP

Total Posts

2.6K

Likes

386

Correct Answer

485

Avatar

radzmar

MVP

Total Posts

2.6K

Likes

386

Correct Answer

485
radzmar
MVP

29-10-2018

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

Answers (5)

Answers (5)

Avatar

Avatar

MinusZero

Avatar

MinusZero

MinusZero

29-10-2018

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

Avatar

Avatar

radzmar

MVP

Total Posts

2.6K

Likes

386

Correct Answer

485

Avatar

radzmar

MVP

Total Posts

2.6K

Likes

386

Correct Answer

485
radzmar
MVP

29-10-2018

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

Avatar

Avatar

johnnyp32387969

Avatar

johnnyp32387969

johnnyp32387969

29-10-2018

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

Avatar

radzmar

MVP

Total Posts

2.6K

Likes

386

Correct Answer

485

Avatar

radzmar

MVP

Total Posts

2.6K

Likes

386

Correct Answer

485
radzmar
MVP

29-10-2018

Indeed!

Avatar

Avatar

johnnyp32387969

Avatar

johnnyp32387969

johnnyp32387969

29-10-2018

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