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

Text summary via loop through?

TavC
Level 1
Level 1

Hi,

I'm trying to generate a text summary field at the end of a form. The form has many sections which could be shown, hidden, or duplicated so I assume the best way is to do a loop through of all the visible form objects - rather than telling the summary field to get field values at defined locations, tell it to go look for what's there and report back.

The summary format is "caption = value; caption = value;" etc

It could run on a button click, though to prevent differences between the field value and the summary value, ideally this would run live, e.g. on the calculate event of the summary field.

Any help gratefully received!

1 Accepted Solution
_Bruce_Robertson
Correct answer by
Level 10
Level 10

Hi,

Maybe this code will get you started, it goes though your form page by page, then every field on the page and displays an alert of the field caption and value for each field that is visible.

function isNodeVisible(node) {

    for (; node.somExpression !== "xfa[0].form[0]"; node = node.parent) {

        if (node.presence == "hidden" || node.presence == "invisible") {

            return false;

        }

    }

    return true

}

for (var i = 0; i < xfa.host.numPages; i++) {

    var fields = xfa.layout.pageContent(i, "field");

    for (var j = 0; j < fields.length; j++) {

        if (isNodeVisible(fields.item(j))) {

            if (fields.item(j).ui.oneOfChild.className != "button") {

                app.alert(fields.item(j).caption.value.text.value + " " + fields.item(j).rawValue);

            }

        }

    }

}

You will need to do some more work to get the caption if you have any radio buttons

Regards

Bruce

View solution in original post

2 Replies
_Bruce_Robertson
Correct answer by
Level 10
Level 10

Hi,

Maybe this code will get you started, it goes though your form page by page, then every field on the page and displays an alert of the field caption and value for each field that is visible.

function isNodeVisible(node) {

    for (; node.somExpression !== "xfa[0].form[0]"; node = node.parent) {

        if (node.presence == "hidden" || node.presence == "invisible") {

            return false;

        }

    }

    return true

}

for (var i = 0; i < xfa.host.numPages; i++) {

    var fields = xfa.layout.pageContent(i, "field");

    for (var j = 0; j < fields.length; j++) {

        if (isNodeVisible(fields.item(j))) {

            if (fields.item(j).ui.oneOfChild.className != "button") {

                app.alert(fields.item(j).caption.value.text.value + " " + fields.item(j).rawValue);

            }

        }

    }

}

You will need to do some more work to get the caption if you have any radio buttons

Regards

Bruce

View solution in original post

TavC
Level 1
Level 1

Much obliged Bruce - thank you! I do have radios in the form, but this script is great to get going with.