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

Text Field Caption Number Increment - Will not load correctly after saving

Avatar

Level 1

I'm trying to create a dynamic caption field that essential will make the text fields look like a list.  At first I searched on how to do this.  I eventually found a way to do it, and that is simply to to count how many instances of the text field I have and set the caption value:

     var curObject = prospectus.page1.step1.ObjectivesSubform.Objectives.instanceManager.count;
     prospectus.page1.step1.ObjectivesSubform.Objectives[curObject-1].Objective.caption.value.text.value = concat(curObject, ":");

And that allows my form to work very well and the numbers to load very well in the form.  The trouble that I'm having is that after I save the form and reload it, the numbers go back to 1 for each text field.  Anyone have an idea?

*To test what I'm seeing, simply go to "Project Objectives" and click Add Objective to create at least 2 extra text fields (so that you have at least 3 overall).  Save the form and notice that the numbers have gone from 1,2,3 to 1,1,3.  This will be the same if you create any amount.  If you create 5 more it will go 1,1,1,1,5.  I'm stumped.

1 Accepted Solution

Avatar

Correct answer by
Level 10

I believe it is related to the initialization of the sub-form and how the instance manager interprets the sub-form count. The 'count' property on the instanceManager is the current number of instances of the sub-form. As you add instances of the sub-form the 'count' increments and it is exposed as an incrementing sequential number. However, after saving-closing-opening the form, the count is not relevent until you add another instance.

Try the property 'instanceIndex' and assigning the caption as follows:

// prospectus.page1.step1.ObjectivesSubform.Objectives.Objective::initialize - (JavaScript, client)

var cnt = Objectives.instanceIndex + 1;
xfa.resolveNode("Objectives.Objective.caption.value.#text").value = cnt + ":";

Steve

PLEASE NOTE THERE ARE PROBLEMS ON THIS FORM I DID NOT HAVE A CHANCE TO LOOK AT.

View solution in original post

0 Replies

Avatar

Correct answer by
Level 10

I believe it is related to the initialization of the sub-form and how the instance manager interprets the sub-form count. The 'count' property on the instanceManager is the current number of instances of the sub-form. As you add instances of the sub-form the 'count' increments and it is exposed as an incrementing sequential number. However, after saving-closing-opening the form, the count is not relevent until you add another instance.

Try the property 'instanceIndex' and assigning the caption as follows:

// prospectus.page1.step1.ObjectivesSubform.Objectives.Objective::initialize - (JavaScript, client)

var cnt = Objectives.instanceIndex + 1;
xfa.resolveNode("Objectives.Objective.caption.value.#text").value = cnt + ":";

Steve

PLEASE NOTE THERE ARE PROBLEMS ON THIS FORM I DID NOT HAVE A CHANCE TO LOOK AT.

Avatar

Level 1

That works perfectly. Instead of having the instanceManager 'count' how many nodes there are, just ask it to return the instanceIndex of the current node. Thank you Steve.