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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Autonumber field based on subform container visibility - dynamic changes not updating numbering system

Avatar

Level 3

Requesting assistance to debug on calculate event for a numeric field to change the numbering if the subform is visible or hidden, I have the following code in the numeric field on the calculate event:

form1.PageOneSub.Subform1.SectionNumber::calculate - (JavaScript, client)

var visibleIndex = 1;

for (var i = 0; i < parent.classIndex; i++) {

    var section = parent.classAll.item(i);

    if (section.presence == "visible") {

        visibleIndex++;

    }

}

 

form1.PageOneSub.Subform2.SectionNumber::calculate - (JavaScript, client)

var visibleIndex = 1;

for (var i = 0; i < parent.classIndex; i++) {

    var section = parent.classAll.item(i);

    if (section.presence == "visible") {

        visibleIndex++;

    }

}

While the code above works and displays the numbering from 1 on, and, is correct for the subforms; any hiding of existing subforms does not trigger an update to the numbered list.

I have used the start of the index at 1 as otherwise it will display 0 in the first instance.

My subforms are uniquely named and are not iterations as they have custom content and may display based on other answers or button clicks.

Thank you in advance...

1 Accepted Solution

Avatar

Correct answer by
Level 10

You need to tell the form to start a recalculation, since this is only triggered automatically through changed values but not the presence of objects. Add this code to the existing script that controls the presence of your subforms.

 

xfa.form.recalculate(true);

View solution in original post

1 Reply

Avatar

Correct answer by
Level 10

You need to tell the form to start a recalculation, since this is only triggered automatically through changed values but not the presence of objects. Add this code to the existing script that controls the presence of your subforms.

 

xfa.form.recalculate(true);

Avatar

Level 3

This would be on the button to show a section or hide a section, is this correct? I had tried the recalculate and relayout functions previously, however, I may not have executed this script on the action button click event. I will try this to follow the JavaScript to hide or show a subform on the same button click event. Will reply with results.

I appreciate your input, sir.