Autonumber field based on subform container visibility - dynamic changes not updating numbering system | Community
Skip to main content
LucreciousDFF
Level 4
February 21, 2022
Solved

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

  • February 21, 2022
  • 1 reply
  • 749 views

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...

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by radzmar

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);

1 reply

radzmar
radzmarAccepted solution
Level 10
February 21, 2022

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);
LucreciousDFF
Level 4
February 22, 2022

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.