Expand my Community achievements bar.

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
Former Community Member

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

2 Replies

Avatar

Correct answer by
Former Community Member

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.

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----