Expand my Community achievements bar.

SOLVED

Add/Remove instance manager issues

Avatar

Level 3

My add instance button is working as intended.

The remove instance button is working, but not as I would like it to. The instance it removes is not necessarily the last instance added, as I would like. When "clicked" it removes the second instance listed. This is a problem when you add 5 or so instances, and need to remove the last one, and end up having to remove all of them because removing the #2 instance just messed up the order of instances.

If this is not making sense I can show you what I'm referring to by uploading/sending interested parties the form.

Here is the "click" event javascript code. I adopted the code from the remove instance manager example, maybe I did not convert it correctly to my form. Not sure why it deletes from the first instance down, instead of last instance up. Any help is appreciated.

var nNumSub = 0;

var nSubLength = Subform1.nodes.length;

for (var nCount = 0; nCount < nSubLength; nCount ++)  {

     if (Subform1.nodes.item(nCount).className == "subform"  {

          nNumSub = nNumSub + 1;

          }

}

nNumSub = nNumSub - 1;

if (nNumSub < 1)  {

    xfa.host.messageBox("The minimum allowable number of subforms is 1. You cannot remove any more subforms.", "Warning", 3);

}

else {

     Subform1.Subform2.SubformImpression.instanceManager.removeInstance(nNumSub);

}

Thank you,

B

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

If you want to remove the last one why not use the count method on the instance Manager. This will give you a count of subforms that are displayed (it is 1 based), then subtract 1 to get the instance number for the last subform.

nNumSub =  Subform1.Subform2.SubformImpression.instanceManager.count

Paul

View solution in original post

4 Replies

Avatar

Correct answer by
Former Community Member

If you want to remove the last one why not use the count method on the instance Manager. This will give you a count of subforms that are displayed (it is 1 based), then subtract 1 to get the instance number for the last subform.

nNumSub =  Subform1.Subform2.SubformImpression.instanceManager.count

Paul

Avatar

Level 3

That script does nothing as a replacement script or added to my original script.

It still deletes instances starting at the top.

Perhaps I missed something.

EDIT: Added the -1 to the end of it and worked perfectly when added in parenthesis to my original script.

Thanks again Paul.

Avatar

Level 3

Paul,

So I want to do the same thing, but my instance manager set-up is much simpler:

form1.QuickNoteGathering.Data.Button1::click - (JavaScript, client)

Data.Info.instanceManager.addInstance(1);

So what code would I use to have a button that removes the last instance added?

Also, I want the instances to continue on to several pages if needed (i.e.: my outlay is just a small sample and one can add as many additional information layers as they need). But it all goes awray as it comes to the buttom of the first page. So I can I assure that as you click the add additional info, it will persist to as many pages as needed?

Thanks. I can send you the form if you need me too, since there is no upload anymore to this forum.

thanks

Shai

Avatar

Level 3

Paul has helped me with issue. Here's the code.

Table1.detail.instanceManager.removeInstance(Table1.detail.instanceManager.count -1)

To make your table continues to second page, Make sure your form is Dynamic and set to Flowed.

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